classSolution:deffindAnagrams(self,s:str,p:str) -> List[int]: res =[] need ={} window ={}for c in p: need[c]= need.get(c, 0)+1 left =0# 窗口左边界 right =0# 窗口右边界 start =0# 记录子串起点 valid =0# p串与s串匹配次数while right <len(s):# 增大窗口 c = s[right] right +=1if c in need:# 该字符在p串中 window[c]= window.get(c, 0)+1if window[c]== need[c]:# 该字符匹配 valid +=1while right-left >=len(p):#缩小窗口if valid ==len(need):#完全匹配时,将左侧边界填入结果 res.append(left) d = s[left] left +=1if d in need:if window[d]== need[d]: valid -=1 window[d]-=1return res