From abbeb270c74f51a2e21ef4463c991be2280d09d9 Mon Sep 17 00:00:00 2001 From: JungHwan Date: Tue, 23 Jul 2024 22:17:58 +0900 Subject: [PATCH] 7/23 1Q --- JungHwan/Day23/NeetCode_PermutationString.py | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 JungHwan/Day23/NeetCode_PermutationString.py diff --git a/JungHwan/Day23/NeetCode_PermutationString.py b/JungHwan/Day23/NeetCode_PermutationString.py new file mode 100644 index 0000000..9bfe389 --- /dev/null +++ b/JungHwan/Day23/NeetCode_PermutationString.py @@ -0,0 +1,31 @@ +class Solution: + def checkInclusion(self, s1: str, s2: str) -> bool: + l, r = 0, 0 + cnt, window = {}, {} + for i in s1: + Solution.addDict(cnt, i) + print("cnt:",cnt) + + while r < len(s2): + print("l,r:",l,r) + Solution.addDict(window, s2[r]) + if r >= len(s1): + Solution.removeDict(window, s2[l]) + l += 1 + r += 1 + print("window:",window) + if cnt == window: + return True + return False + + def addDict(d: dict, s: str): + if s in d: + d[s] += 1 + else: + d[s] = 1 + + def removeDict(d: dict, s: str): + if d[s] == 1: + del d[s] + else: + d[s] -= 1 \ No newline at end of file