leetcode:
重复的子字符串
暴力算法:
public boolean repeatedSubstringPattern(String s) {
if(s.length() < 1)
return false;
int len = 1;
int strLen = s.length();
int i = 0;
while(len <= strLen/2){
if(strLen%len != 0){
len++;
continue;
}
String subStr = s.substring(0,len);
i = 0;
for(i = len;i < strLen;i += len){
if(!subStr.equals(s.substring(i, i+len))){
break;
}
}
if(i >= strLen)
return true;
len++;
}
return false;
}
看了之后知道是怎么写,但是自己写的时候却又写不出,哎,尴尬
网友评论