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
相关文章
- 03-04【LeetCode】1047. Remove All Adjacent Duplicates In String 解题报告(Python)
- 03-04【leetcode❤python】 438. Find All Anagrams in a String
- 03-04【LeetCode】438. Find All Anagrams in a String 解题报告(Python)
- 03-04438. Find All Anagrams in a String
- 03-04438. Find All Anagrams in a String
- 03-04【leetcode】438. Find All Anagrams in a String
- 03-04(转)leetcode:Find All Anagrams in a String 滑动窗口方法总结
- 03-04【leetcode】438. Find All Anagrams in a String
- 03-04Leetcode.438 Find All Anagrams in a String(Java)
- 03-04【easy】438.Find All Anagrams in a String 找出字符串中所有的变位词