class Solution:
    def checkInclusion(self, s1, s2):
        n, m = len(s1), len(s2)
        if n>m: return False
        str1 = collections.Counter(s1)
        str2 = {}
        for i in range(n):
            val = str2.get(s2[i], 0)
            if val == 0:
                str2[s2[i]] = 1
            else:
                str2[s2[i]] += 1
        if str2 == str1: return True
        for i in range(n, m):
            val = str2.get(s2[i-n], 0)
            if val == 1:
                str2.pop(s2[i-n])
            else:
                str2[s2[i-n]] -= 1
            val = str2.get(s2[i], 0)
            if val == 0:
                str2[s2[i]] = 1
            else:
                str2[s2[i]] += 1
            if str1 == str2: return True
        return False