class Solution:
def strStr(self, haystack: str, needle: str) -> int:
lenh = len(haystack)
lenn = len(needle)
if lenh == lenn and haystack == needle:
return 0
elif lenh < lenn:
return -1
checkrange = lenh - lenn + 1
for i in range(checkrange):
if haystack[i:i+lenn] == needle:
return i
else:
return -1
Leetcode刷题记录——28. 实现 strStr()
猜你喜欢
转载自blog.csdn.net/weixin_41545780/article/details/105478992
今日推荐
周排行