赞
踩
class Solution(object): def findSubstring(self, s, words): """ :type s: str :type words: List[str] :rtype: List[int] """ if words==[]: return [] res=[] adict={} l=len(words[0]) count=len(words) ls=len(s) dp1=[0]*count for index in range(count): ws=words[index] if ws in adict: index=adict[ws] else: adict[ws]=index dp1[index]+=1 for i in range(len(s)-l*count+1): curl=i dp=dp1[:] while curl+l<=ls and s[curl:curl+l] in adict: index=adict[s[curl:curl+l]] dp[index]-=1 if dp[index]<0: break curl+=l if curl-i==count*l: res.append(i) return res
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。