题目:
python3代码:
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
if (len(haystack) == 0 and len(needle) == 0) or (len(haystack) != 0 and len(needle) == 0):
return 0
if len(haystack) < len(needle):
return -1
for i in range(len(haystack)-len(needle)+1):
if haystack[i:i+len(needle)] == needle:
return i
return -1
如果觉得不错,就点赞或者关注或者留言~
谢谢~