1. 程式人生 > >CRCK array 1.8

CRCK array 1.8

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”).

// Nothing difficult on this problem.
// supposed the input is ""waterbottle", its rotation is "erbottlewat"
// example: rotation + rotation = erbottles"waterbottle"wat. 
bool checkRotation(string s1, string s2) {
    string s3 = s2 + s2;
    return isSubstring(s1, s3);
}