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
相关文章
- [LeetCode] 438. Find All Anagrams in a String_Easy
- find-all-anagrams-in-a-string
- 438. Find All Anagrams in a String
- 【LeetCode】833. Find And Replace in String 解题报告(Python)
- Find All Anagrams in a String
- 【leetcode❤python】 438. Find All Anagrams in a String
- 【easy】438.Find All Anagrams in a String 找出字符串中所有的变位词
- [LeetCode] 438. Find All Anagrams in a String 找出字符串中所有的变位词
- [LeetCode] Find All Anagrams in a String 找出字符串中所有的变位词
- LeetCode算法题-Find All Anagrams in a String(Java实现)