Permutation in String
固定长度的双指针题,核心思路还是RabinKarp型的移动字符串对比
class Solution(object):
def checkInclusion(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
m, n = len(s1), len(s2)
dictM = collections.Counter(s1)
dictN = collections.Counter(s2[:m])
for i in xrange(n - m + 1):
if dictM == dictN:
return True
if i < n - m:
dictN[s2[i]] -= 1
if not dictN[s2[i]]:
dictN.pop(s2[i])
dictN[s2[i + m]] += 1
return False