Created
February 29, 2024 00:27
-
-
Save mvallebr/056e38e529bb4af827c24b43fa5ce2cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter, defaultdict | |
class Solution: | |
def checkInclusion(self, s1: str, s2: str) -> bool: | |
original_letters = Counter(s1) | |
letters = defaultdict(int) | |
temp = deque() | |
for current_letter in s2: | |
temp.append(current_letter) | |
letters[current_letter] += 1 | |
if len(temp) > len(s1): | |
letters[temp.popleft()] -= 1 | |
if all(letters[l] == original_letters[l] for l in original_letters.keys()): | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment