void getNext(int* next,const string& s)
{
//j为前缀末尾
int j =0;
//next[0]表示单个元素相等前后缀长度,一定为0
next[0] = 0;
//i为后缀末尾,从1开始
for(int i=1;i<s.size();i++)
{
while(j>0 && s[i]!=s[j])
{
j = next[j-1];
}
if(s[i]==s[j])
{
j++;
}
next[i] = j;
}
}
02-14
312
08-06
3709
07-27
1万+
07-16
643
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交