Python O(n) 4 Line Solution Simple

  • -1
    def strStr(self, haystack, needle):
        if not needle in haystack:
            return -1
            return haystack.index(needle)

  • 0

    That's not O(n). Unless you define n as the product of the string lengths, which would be very weird.

Log in to reply

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