classSolution(object):deffindSubstring(self, s, words):if words==[]:return []
n,k,words_len = len(s),len(words[0]),len(words)
type_suc,type_fail=1,0
result,words_,initial = [],{},set()
defparse(start):
hash_words = words_.copy()
while start+k<=n:
ch = s[start:start+k]
if hash_words.get(ch,-1)>0:
hash_words[ch]-=1else:
return type_fail
start+=k
return type_suc
definit():nonlocal initial,words_
for word in words:
initial.add(word[0])
if word in words_:
words_[word]+=1else:
words_[word] = 1
start = 0
init()
while n-start>=words_len*k:
if s[start] in initial:
return_type = parse(start)
if return_type==type_suc:
result.append(start)
Next,index = [],0
start+=1return result