题目描述:
解决代码如下:
class Solution(object):
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
lh = len(haystack)
ln = len(needle)
if ln == 0:
return 0
if lh == 0 or lh < ln:
return -1
i = 0
while(i<=lh-ln):
if haystack[i] == needle[0]:
if haystack[i:i+ln] == needle:
return i
else:
i = i+1
else:
i += 1
return -1
提交结果:
来源:CSDN
作者:陆云杰
链接:https://blog.csdn.net/lu_yunjie/article/details/104284253