Use python str.split function :P

  • 0
        if len(needle) == 0:
            return 0
        elif len(haystack) == 0:
            return -1
        parts = haystack.split(needle)
        #if only one parts, there is no parts matching needle. Otherwise return the index just before split happens
        if len(parts ) == 1:
            return -1
            return len(parts[0])

Log in to reply

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