We are given two strings, A
and B
.
A shift on A
consists of taking string A
and moving the leftmost character to the rightmost position. For example, if A = 'abcde'
, then it will be 'bcdea'
after one shift on A
. Return True
if and only if A
can become B
after some number of shifts on A
.
Example 1: Input: A = 'abcde', B = 'cdeab' Output: true Example 2: Input: A = 'abcde', B = 'abced' Output: false
Note:
A
andB
will have length at most100
.
bool rotateString(char* A, char* B) {
int a,b;
a=strlen(A);
b=strlen(B);
int i,j,k;
char t;
if(a!=b)
return false;
if(a==0)
return true;
for(i=0;i<a;i++)
{
t=A[a-1];
for(k=a-1;k>0;k--)
{
A[k]=A[k-1];
}
A[0]=t;
if(strcmp(A,B)==0)
return true;
}
return false;
}