class Solution(object):
def checkInclusion(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
# 滑动窗口
# 这个题与28是同类的,都是定长的滑动窗口问题
# 不同在于,此题考虑到排列,排列乍一看比较麻烦,需要考虑的情况很多
# 我们可以用字典来表示,不管如何排列,只要每个字符都一样,那么肯定可以排列出来
# 引用collections中的Counter来作为字典,进行排序的判断
star = 0
from collections import Counter
temp = Counter(s1)
for end in range(len(s1)-1, len(s2)):
if Counter(s2[star:end+1]) == temp:
return True
star += 1
return False
滑动窗口-3--LC567.字符串的排列
最新推荐文章于 2024-07-09 23:43:07 发布