Problem:
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”).
这个问题的trick就是将两个原字符串拼起来,然后检测。。。
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”).
这个问题的trick就是将两个原字符串拼起来,然后检测。。。

本文介绍了一种利用isSubstring方法检查一个字符串是否为另一个字符串的旋转的方法。通过将原字符串连接自身,再使用isSubstring方法判断目标字符串是否存在于其中,以此来高效地解决该问题。
605

被折叠的 条评论
为什么被折叠?



