Given two strings s
and goal
, return true
if and only if s
can become goal
after some number of shifts on s
.
A shift on s
consists of moving the leftmost character of s
to the rightmost position.
- For example, if
s = "abcde"
, then it will be"bcdea"
after one shift.
Example 1:
Input: s = "abcde", goal = "cdeab" Output: true
Example 2:
Input: s = "abcde", goal = "abced" Output: false
Solution :
bool rotateString(string s, string goal) {
string tmp = s+s;
if(s.length() != goal.length())
return false;
if(tmp.find(goal) != string::npos)
return true;
return false;
}
Complete Code:
/*
Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.
A shift on s consists of moving the leftmost character of s to the rightmost position.
For example, if s = "abcde", then it will be "bcdea" after one shift.
Example 1:
Input: s = "abcde", goal = "cdeab"
Output: true
Example 2:
Input: s = "abcde", goal = "abced"
Output: false
*/
#include <bits/stdc++.h>
using namespace std;
bool checkRotation(string s1, string s2) {
string tmp = s1+s1;
if(s1.length() != s2.length())
return false;
cout << tmp << " : " << s2 << endl;
if(tmp.find(s2) != string::npos)
return true;
return false;
}
int main()
{
string str1 = "abcde";
string str2 = "abced";
cout << checkRotation(str1, str2) << endl;
return 0;
}
I was pretty pleased to discover this great site. I want to to thank you for ones time due to this fantastic read!! I definitely appreciated every part of it and I have you book marked to look at new stuff on your web site.
hawaii drinking before surgery
https://trendingsimple.com/hawaii/what-is-the-perfect-gift-for-someone-moving-to-hawaii/#what-is-a-hawaiian-kiss
I was very happy to discover this great site. I need to to thank you for your time for this particularly wonderful read!! I definitely liked every part of it and I have you bookmarked to check out new information on your blog.
Good day! I simply want to offer you a big thumbs up for the excellent info youve got right here on this post. Ill be coming back to your site for more soon.