CC189 - 1.9

1.9 StringRotation:Assumeyouhaveamethodi5Sub5tringwhichchecksifonewordisasubstring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to i5Sub5tring (e.g., "waterbottle" is a rotation of" erbottlewat").

Highlight:
check rotation -> s2 is a subtring of s1s1

bool isRotation(string str1, string str2){
    if(str1.size()!=str2.size()) return false;
    string s1s1 = str1 + str1;
    if(s1s1.find(str2)!=string::npos){
        return true;
    }
    return false;
}

https://onlinegdb.com/r1AD0nCo4

猜你喜欢

转载自blog.csdn.net/real_lisa/article/details/89923001
1.9
今日推荐