Assume you have a method isSubstring which checks if one word is a substring
of another. Given two strings, si and s2, write code to check Ifs2 is a rotation of si
using only onecalltoisSubstring (e.g., "waterbottLe" is a rotation of "erbottLewat").
soln : 链接起来看看是不是substring
public class JumpTwo {
public static void main(String[] args) {
String s1 = "waterbottle";
String s2 = "bottlewater";
String s = s1+s1;
if(isSubstring(s2,s)) {
System.out.println("yes");
System.out.println(s);
}else System.out.println("no");
}
private static boolean isSubstring(String str, String target) {
if(str.equals(target)) return true;
if(str.length()>target.length()) return false;
return isSubstring(str,target.substring(1,target.length()))||isSubstring(str,target.substring(0,target.length()-1));
}
}