Brute force Python solution


  • 0
    C
    def strStr(self, haystack, needle):
            if not needle: return 0
            for i in range(len(haystack) - len(needle) + 1):
                for j in range(len(needle)):
                    if haystack[i + j] != needle[j]:
                        break
                    elif j == len(needle) - 1:
                        return i
            return -1
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.