class Solution:
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
if(needle==''):
return 0
if(len(needle)>len(haystack)):
return -1
l=len(haystack)-len(needle)+1
for i in range(0,l):
if(haystack[i:len(needle)+i]==needle):
#if(haystack.substr(i,len(needle)))==needle:
return i
return -1
python版Leetcode28 实现str
最新推荐文章于 2022-11-09 22:31:31 发布