思路:
// @Title: 重复的子字符串 (Repeated Substring Pattern)
// @Author: qisiii
// @Date: 2024-09-13 23:34:26
// @Runtime: 14 ms
// @Memory: 43.7 MB
// @comment:
// @flag:
class Solution {
public boolean repeatedSubstringPattern(String s) {
int j=1;
while(true){
while(j<s.length()&&s.charAt(0)!=s.charAt(j)){
j++;
}
if(j>s.length()/2){
return false;
}
int k=0;
boolean match=true;
for(k=j;k<s.length();k++){
if(s.length()%j!=0||s.charAt(k)!=s.charAt(k-j)){
match=false;
break;
}
}
if(match){
return true;
}
j++;
}
}
}
思路:
// @Title: 重复的子字符串 (Repeated Substring Pattern)
// @Author: qisiii
// @Date: 2024-09-13 23:16:08
// @Runtime: 64 ms
// @Memory: 44.1 MB
// @comment:
// @flag:
class Solution {
public boolean repeatedSubstringPattern(String s) {
int j=1;
while(true){
while(j<s.length()&&s.charAt(0)!=s.charAt(j)){
j++;
}
if(j>s.length()/2){
return false;
}
String str=s.substring(0,j);
int k=0;
for(k=j;k<s.length();k=k+j){
if(!str.equals(s.substring(k,Math.min(k+j,s.length())))){
break;
}
}
if(k==s.length()){
return true;
}
j++;
}
}
}
思路:暴力且使用substring
// @Title: 重复的子字符串 (Repeated Substring Pattern)
// @Author: qisiii
// @Date: 2024-09-13 22:32:53
// @Runtime: 73 ms
// @Memory: 44.2 MB
// @comment: 暴力且使用substring
// @flag: WHITE
class Solution {
public boolean repeatedSubstringPattern(String s) {
int j=1;
while(true){
while(j<s.length()&&s.charAt(0)!=s.charAt(j)){
j++;
}
if(j==s.length()){
return false;
}
String str=s.substring(0,j);
int k=0;
for(k=j;k<s.length();k=k+j){
if(!str.equals(s.substring(k,Math.min(k+j,s.length())))){
break;
}
}
if(k==s.length()){
return true;
}
j++;
}
}
}