class Solution:
def strStr(self, haystack: str, needle: str) -> int:
n,m=len(haystack),len(needle)
if m==0:
return 0
if haystack==needle:
return 0
for i in range(n-m+1):
if haystack[i:i+m]==needle:
return i
return -1
自行了解KMP或者BM吧