Leetcode brushing record-28. Implementar strStr ()

Inserte la descripción de la imagen aquí

class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        
        lenh = len(haystack)
        lenn = len(needle)
        if lenh == lenn and haystack == needle:
            return 0
        elif lenh < lenn:
            return -1
        checkrange = lenh - lenn + 1
        for i in range(checkrange):
            if haystack[i:i+lenn] == needle:
                return i
        else:
            return -1
59 artículos originales publicados · Me gustaron 14 · Visitantes más de 20,000

Supongo que te gusta

Origin blog.csdn.net/weixin_41545780/article/details/105478992
Recomendado
Clasificación