Simple python solution

  • 0

    class Solution(object):
    def strStr(self, haystack, needle):
    :type haystack: str
    :type needle: str
    :rtype: int

        total_length = 0
        if needle == "":
            return 0
        for index, word in enumerate(haystack.split(" ")):
            if needle in word:
                return total_length + index + word.index(needle)
                total_length += len(word)
        return -1

Log in to reply

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