您的位置:首页 > 其它

CRCK array 1.8

2016-03-27 06:07 288 查看
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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: