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
おすすめ
ランキング