void build(int* next,char* s,int n){
next[0]=-1;
int index=1,j=-1;
while(index<n){
if(j==-1 || s[index-1] == s[j]){
j++;
next[index++]=j;
}else{
j=next[j];
}
}
for(int i=0;i<n;i++) printf("%d ",next[i]);
}
bool repeatedSubstringPattern(char* s) {
int n=strlen(s);
if(n==1) return false;
int* next=(int*)malloc(sizeof(int)*n);
build(next,s,n);
int t=next[n-1];
if(s[t]!=s[n-1]) return false;
t++;
if(n%(n-t)!=0 ) return false;
return true;
}
标签:459,index,int,next,重复,字符串 From: https://www.cnblogs.com/llllmz/p/18083276