A[1~N]是否为B[1~M]的子串
next[1]=0; for(int i=2,j=0;i<=n;i++) { while(j>0&&a[i]!=a[j+1]) j=next[j]; if(a[i]==a[j+1]) j++; next[i]=j; } for(int i=1,j=0;i<=m;i++) { while(j>0&&(j==n||b[i]!=a[j+1])) j=next[j]; if(b[i]==a[j+1]) j++; f[i]=j; //if(f[i]==n) A在B中出现一次 }
原文:https://www.cnblogs.com/ChildeZhe/p/12209931.html