思路:
// @Title: 旋转字符串 (Rotate String)
// @Author: qisiii
// @Date: 2024-09-13 01:38:58
// @Runtime: 0 ms
// @Memory: 40.4 MB
// @comment:
// @flag:
class Solution {
public boolean rotateString(String s, String goal) {
return s.length()==goal.length()&&(s+s).contains(goal);
}
}
思路:
// @Title: 旋转字符串 (Rotate String)
// @Author: qisiii
// @Date: 2024-09-13 00:44:32
// @Runtime: 0 ms
// @Memory: 40.4 MB
// @comment:
// @flag:
class Solution {
public boolean rotateString(String s, String goal) {
if(s.equals(goal)){
return true;
}else if(s.length()!=goal.length()){
return false;
}
int start=0;
for(int second=0;second<goal.length();second++){
start=0;
if(goal.charAt(second)!=s.charAt(start)){
continue;
}
int temp=second;
while(start<s.length()){
if(s.charAt(start)!=goal.charAt(temp)){
break;
}
start++;temp++;
if(temp>=goal.length()){
temp=0;
}
}
if(start==s.length()){
return true;
}
}
return false;
}
}