Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring (i.e., “waterbottle” is a rotation of “erbottlewat”).
注意rotate是字符串左移或者右移n位
解法很巧妙,拼接2个s1,判断s2是否是s1s1的子串。
bool isRotation(string s1, string s2)
{
if(s1.size()!=s2.size() || s1.size()==0 ||s2.size()==0)
return false;
string s1s1=s1+s1;
if (isSubstring(s1s1, s2))
return true;
else
return false;
}