题目描述:
思路:
首先找到A中与B的第一个字符相等的位置,从这个位置开始查找,比较
代码如下:
class Solution {
public:
bool rotateString(string A, string B) {
if(A.size()!=B.size()) return false;
if(A.size()==0&&B.size()==0) return true;
vector<int>same;
for(int i=0;i<A.size();i++){
if(A[i]==B[0])
same.push_back(i);
}
for(int i=0;i<same.size();i++){
int j=0;
int temp=same[i];
while(j<B.size()){
if(B[j]==A[temp]){
j++;
temp++;
if(temp==A.size())
temp-=A.size();}
else break;
}
if(j==B.size())
return true;
}
return false;
}
};