时间复杂度O(n + pm),其中n是s1的长度,p是字符s2[0]在s1出现的次数,m是s2的长度;
空间复杂度O(1)
bool solution(string s1, string s2)
{
int j = 0;
while (j < s1.length())
{
while (j < s1.length() && s1[j] != s2[0])
{
j++;
}
if (j >= s1.length())
return false;
int k = 0, m = j;
while (k < s2.length() && s1[m] == s2[k])
{
k++;
m = (m + 1) % s1.length();
}
if (k == s2.length())
return true;
j++;
}
return false;
}