class Solution:
def strStr(self, haystack: str, needle: str) -> int:
# 分辨needle是不是为NOne或是为空字符串
if not needle or len(needle) == 0:
return 0
# 界定2个自变量,用于接受needle的长短
length,index = len(needle),0
# 开展循环系统 ,当index的值
while index <= len(haystack) - length:
# 分辨是不是能够 配对
if haystack[index : index length] == needle:
return index
# 数据库索引加一
else:
index = 1
# 意味着配对不成功,回到-1
return -1

A = Solution()
print(A.strStr("hello","ll"))
print(A.strStr("helll","hahah"))
本文版权归QU快排Www.seoGurubLog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ▲61910465