28.Implement strStr()

 

 

class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        if len(needle) == 0:
            return 0
        else:
            for i in range(len(haystack)):
                if haystack[i: i+len(needle)] == needle :
                    return i
            return -1

 

posted @ 2020-05-09 15:20  星海寻梦233  阅读(70)  评论(0编辑  收藏  举报