j nextp[j] ##needle[naxpt[j]-1] needle[i-1]!!!
## 因为needle[i-1] needle[j-1],连续比较的规律
i j 0
#print(nextp)
while(j L2 and i L1):
if (j -1) or (haystack[i] needle[j]):
if j L2:
return i-j
continue
else:
j nextp[j]
if j -1 and (L1-1-i) L2: ##剩余长度不够
return -1
return -1
可能相比于优化过的切片方法 本方法还是很慢。但暴力法会超时