Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created February 29, 2024 00:27
Show Gist options
  • Save mvallebr/056e38e529bb4af827c24b43fa5ce2cc to your computer and use it in GitHub Desktop.
Save mvallebr/056e38e529bb4af827c24b43fa5ce2cc to your computer and use it in GitHub Desktop.
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