Solution 1

Python
class Solution:
    def checkInclusion(self, s1: str, s2: str) -> bool:
        need = Counter(s1)
        have = Counter(s2[:len(s1)-1])
        i = 0
        for c in s2[len(s1)-1:]:
            have[c] = have.get(c, 0) + 1
            if need == have: return True
            have[s2[i]] -= 1
            i += 1
        return need == have
Leet Code/python.py · L547–558