假设有一个方法isSubstring, 可检查一个单词是否为其他字符串的子串。给定两个字符串s1和s2,请编写代码检查s2是否为s1旋转而成,要求只能调用一次isSubstring。(比如,waterbottle是erbottlewat旋转后的字符串)。
package test;
public class RotateString {
public static boolean rotateString(String s1, String s2){
if(s1 == null || s2 == null || s1.length() == 0
|| s2.length() == 0 || s1.length()!=s2.length())
return false;
String s1s1 = s1+s1;
return isSubstring(s2, s1s1);
}
}