判断字符串s1是否为s2的旋转字符串(”waterbottle”是”erbottlewat”的旋转字符串)。

1
2
3
4
5
6
7
8
9
10
11
12
13
public class Question{
public static void main(String[] args){
String s1 = "waterbottle";
String s2 = "erbottlewat";
boolean result = isRotation(s1, s2);
System.out.println(s1 + " is a rotation of " + s2 + "? " + result);
}
public static boolean isRotation(String s1, String s2){
String s3 = s2 + s2;
return s3.indexOf(s1) >= 0;
}
}

需要充分理解旋转字符串的含义