题目来源于力扣(LeetCode)
说明:
A
和B
长度不超过100
。
字符串 A 拼接两次后形成的字符串中一定包含了旋转后的字符串
两个字符串长度一致且字符串 B 存在于字符串 A 拼接两次后形成的字符串中时,返回 false
public static boolean rotateString(String A, String B) {
return A.length() == B.length() && (A + A).contains(B);
}
public static void main(String[] args) {
String A = "abcde", B = "cdeab"; // output: true
// String A = "abcde", B = "abced"; // output: false
boolean result = rotateString(A, B);
System.out.println(result);
}
原文:https://www.cnblogs.com/zhiyin1209/p/13227536.html