28.实现strStr()

class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        for i in range(len(haystack) - len(needle) + 1):
            # 判断needle是否属于haystack中的一部分
            if haystack[i:i+len(needle)] == needle:
                return i
        return -1

 

posted @ 2019-08-20 18:38  我叫郑小白  阅读(85)  评论(0编辑  收藏  举报