1def check_inclusion(s1, s2):
2 if len(s1) > len(s2): return False
3 c1 = {}; c2 = {}
4 for c in s1: c1[c] = c1.get(c, 0) + 1
5 for i in range(len(s1)): c2[s2[i]] = c2.get(s2[i], 0) + 1
6 if c1 == c2: return True
7 left = 0
8 for right in range(len(s1), len(s2)):
9 c2[s2[right]] = c2.get(s2[right], 0) + 1
10 c2[s2[left]] -= 1
11 if c2[s2[left]] == 0: del c2[s2[left]]
12 left += 1
13 if c1 == c2: return True
14 return False