LeetCode28A是否是B的子串

------------恢复内容开始------------

# coding:utf-8
"""
Name : LeetCode28.py
Author  : qlb
Contect : 17801044486@163.com
Time    : 2021/2/7 17:17
Desc:实现 strStr()
"""
class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        haystack = list(haystack)
        needle = list(needle)
        for i in range(len(haystack) - len(needle) + 1):
            if needle == haystack[i:i+len(needle)]:
                return i
        else:
            return -1

 

------------恢复内容结束------------

posted @ 2021-02-07 17:22  qilibin  阅读(59)  评论(0编辑  收藏  举报