796.Rotate String
示例 1:
输入: A = 'abcde', B = 'cdeab'
输出: true
示例 2:
输入: A = 'abcde', B = 'abced'
输出: false
注意:
A 和 B 长度不超过 100。class Solution {
public:
bool rotateString(string A, string B) {
if(A.length()!=B.length()) return false;
unordered_set<string> clusterA;
clusterA.insert(A);
int len=A.length();
for(int k=1;k<len;k++)
{
string tmp;
for(int i=k;i<len;i++ )
tmp+=A[i];
for(int i=0;i<k;i++)
tmp+=A[i];
clusterA.insert(tmp);
//cout<<tmp<<endl;
}
return clusterA.count(B);
}
};Last updated