Python easy and concise solution


  • 0
    def findSubstring(self, s, words):
            if not words: return []
            k = len(words[0])
            res = []
            for left in range(k):
                d = collections.Counter(words)
                for right in range(left + k, len(s) + 1, k):
                    word = s[right - k: right]
                    d[word] -= 1
                    while d[word] < 0:
                        d[s[left:left + k]] += 1
                        left += k
                    if left + k * len(words) == right:
                        res.append(left)
            return res

Log in to reply
 

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