美文网首页
leetcode 28

leetcode 28

作者: xbinng | 来源:发表于2017-11-01 08:54 被阅读0次
    1. Implement strStr()
        def strStr(self, haystack, needle):
            """
            :type haystack: str
            :type needle: str
            :rtype: int
            """
            h = len(haystack)
            n = len(needle)
            for i in range(h - n + 1):
                if haystack[i:i + n] == needle:
                    return i
            return -1
    

    返回needle字符串在haystack字符串出现的第一个位置

    相关文章

      网友评论

          本文标题:leetcode 28

          本文链接:https://www.haomeiwen.com/subject/awrwpxtx.html