答案:利用了XY , YX中第一个XYXY包含了第二个
public class Solution{ public static void main(String[] args){ System.out.println(isRotation("abc","abc")); } public static boolean isSubstring(String str1,String str2){ if(str1.contains(str2) || str2.contains(str1)) return true; return false; } public static boolean isRotation(String str1,String str2){ if(str1.length() != str2.length()) return false; String sum = str1 + str1; return isSubstring(sum,str2); } }
时间: 2024-10-19 13:54:31