题目:
如果一个字符串str,把字符串str前面任意的部分挪到后面形成的字符串叫做str的旋转词。比如str="12345",str的旋转词有"12345"、"23451"、"34512"、"45123"、和"51234"。给定两个字符串a和b,请判断a和b是否互为旋转词。
举例:
a = "cdab", b = "abcd", 返回true
a = "1ab2", b = "ab12", 返回false
a = "2ab1", b = "ab12", 返回true
思路:把要匹配字符串2个相加,如果包含目标字符串就是旋转词,反之,则不是
java代码实现如下
public class RotatingWord {public static void main(String[] args) {String s1="adcd";String s2="cdab";String s3="cdad";System.out.print(isRotatingWord(s1,s2));System.out.print(isRotatingWord(s1,s3));}public static boolean isRotatingWord(Strin