暂记,待更新
public void getNext(int[] next, String s){
int j = -1; //指向前缀
int i = 0; //后缀
next[0] = -1; // -1, 0, ...
// next数组存储当前位置之前字符串的最大相等前后缀长度,也是当前位置回溯时访问的数组下标
// 比如 abcdabd 对应 -1,0,0,0,0,1,2, 第一个字符之前没有字符串,这里写为-1
while(i<s.length()-1){
if(j==-1 || s.charAt(j)==s.charAt(i)){
i++;
j++;
next[i]=j; //next[++i] = ++j;
}else{
j=next[j];
}
}
}