Easy Python solution using Split


  • 1
    M
    class Solution(object):
        def strStr(self, haystack, needle):
            if needle =='':
                return 0
            if needle in haystack:
                return len(haystack.split(needle)[0])
            return -1
    

Log in to reply
 

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