Java代码:
public static int KMP_Index(char [] s , char [] t){
int [] next = next(t);
int i=0,j=0;
while(i<s.length&&j<t.length){
if(j==-1||s[i]==t[j]){
i++;
j++;
}else{
j=next[j];
}
}
if(j<t.length)
return -1;
else
return i-t.length;
}
Java代码:
public static int KMP_Index(char [] s , char [] t){
int [] next = next(t);
int i=0,j=0;
while(i<s.length&&j<t.length){
if(j==-1||s[i]==t[j]){
i++;
j++;
}else{
j=next[j];
}
}
if(j<t.length)
return -1;
else
return i-t.length;
}