修改BF算法,避免遇到s和t为"00000……1"和"0001"时发生最坏情况,即在si和t0匹配后,将后与比较,如果匹配,再从与处开始比较。其中,m指的是t的长度
def indexBF2(s,t):
slen=len(s)
tlen=len(t)
i,j=0,0
while i<slen and j<tlen:
if j==0:
if s[j]==t[j] and s[i+tlen-1]==t[tlen-1]:
i,j=i+1,j+1
题目不全