void build(char* s,int* next,int n){
next[0]=-1;
int i=1,j=-1;
while(i<n){
if(j==-1||s[j]==s[i-1]){
next[i]=j+1;
j++;
i++;
}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(s,next,n);
int t=next[n-1]+1;
if(s[t-1]!=s[n-1]) return false;
if(n%(n-t)!=0) return false;
return true;
}
NEXT数组
标签:459,int,void,next,重复,字符串 From: https://www.cnblogs.com/llllmz/p/18079394