题目:
字符串轮转。给定两个字符串s1和s2,请编写代码检查s2是否为s1旋转而成(比如,waterbottle是erbottlewat旋转后的字符串)。
示例1:
输入:s1 = "waterbottle", s2 = "erbottlewat"
输出:True
示例2:
输入:s1 = "aa", s2 = "aba"
输出:False
代码实现:
class Solution {标签:yyds,return,int,s2,s1,flag,金典,false,LeetCode From: https://blog.51cto.com/u_13321676/5913094
public boolean isFlipedString(String s1, String s2) {
int m = s1.length(), n = s2.length();
if (m != n) {
return false;
}
if (n == 0) {
return true;
}
for (int i = 0; i < n; i++) {
boolean flag = true;
for (int j = 0; j < n; j++) {
if (s1.charAt((i + j) % n) != s2.charAt(j)) {
flag = false;
break;
}
}
if (flag) {
return true;
}
}
return false;
}
}