字符串的排列
目录
字符串的排列
题目:
https://leetcode-cn.com/problems/permutation-in-string/
思路:
滑动窗口加字典
代码:
class Solution(object):
def checkInclusion(self, s1, s2):
= collections.Counter(s1)
counter1 = len(s2)
N = 0
left = len(s1) - 1
right = collections.Counter(s2[0:right])
counter2 while right < N:
+= 1
counter2[s2[right]] if counter1 == counter2:
return True
-= 1
counter2[s2[left]] if counter2[s2[left]] == 0:
del counter2[s2[left]]
+= 1
left += 1
right return False