bool repeatedSubstringPattern(char* s) {
int ns=0;
while(s[ns]!=0) ns++;
if(ns<=1) return false;
bool same =true;
char temp=s[0];
int i=1;
for(;i<ns;i++){
if(s[i]!=temp) same=false;
if(ns%i==0 && i!=1) break;
}
if(i==ns) return same;
int slowhead=0,fasthead=1;
while(fasthead<=ns/2){
int slow=slowhead,fast=fasthead;
while(s[slow]==s[fast]){
slow++;
fast++;
if(fast==ns) return true;
}
fasthead++;
}
if(fasthead>ns/2) return false;
return true;
}
结果:
标签:459,repeatedSubstringPattern,return,重复,字符串,ns From: https://www.cnblogs.com/llllmz/p/18044909