【leetcode❤python】 438. Find All Anagrams in a String

class Solution(object):
    def findAnagrams(self, s, p):
        """
        :type s: str
        :type p: str
        :rtype: List[int]
        """
        reslist=[];sdic={};pdic={}
        ls=len(s)
        lp=len(p)
        
        for i in s[:lp]:
            sdic[i]=sdic.get(i,0)+1
        for i in p[:lp]:
            pdic[i]=pdic.get(i,0)+1
        i=0
        while i<ls-lp:
            if sdic==pdic:reslist.append(i)
            sdic[s[i]]-=1
            if sdic[s[i]]==0:
                del sdic[s[i]]
            sdic[s[i+lp]]=sdic.get(s[i+lp],0)+1
            i+=1
        if sdic==pdic:
            reslist.append(i)
        
        return reslist

上一篇:vue服务端渲染提取css


下一篇:实例PK(Vue服务端渲染 VS Vue浏览器端渲染)