当前位置 : 主页 > 手机开发 > ROM >

数组_leetcode438

来源:互联网 收集:自由互联 发布时间:2021-06-10
#coding=utf-8 # 解题思路:排序 20190302 找工作期间 class Solution: def findAnagrams( self, s, p): """ :type s: str :type p: str :rtype : List[int] """ from collections import Counter s_len, p_len = len(s), len(p) count = p_len p
#coding=utf-8
# 解题思路:排序 20190302 找工作期间

class Solution:
def findAnagrams(self, s, p):
"""
:type s: str
:type p: str
:rtype: List[int]
"""
from collections import Counter
s_len, p_len = len(s), len(p)
count = p_len
pChar = Counter(p)
result = []
for i in range(s_len):
if pChar[s[i]] >= 1:
count -= 1
pChar[s[i]] -= 1
if i >= p_len:
if pChar[s[i - p_len]] >= 0:
count += 1
pChar[s[i - p_len]] += 1
if count == 0:
result.append(i - p_len + 1)
return result
网友评论