From ea73569d11a9a5f0a4be59de9cc18566ad6cb952 Mon Sep 17 00:00:00 2001 From: hyh Date: Wed, 19 Nov 2025 15:08:39 +0900 Subject: [PATCH 1/4] valid anagram --- valid-anagram/deepInTheWoodz.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 valid-anagram/deepInTheWoodz.py diff --git a/valid-anagram/deepInTheWoodz.py b/valid-anagram/deepInTheWoodz.py new file mode 100644 index 0000000000..10a1f4fa3c --- /dev/null +++ b/valid-anagram/deepInTheWoodz.py @@ -0,0 +1,29 @@ +# TC: O(n) +# SC: O(1) +def isAnagram(s: str, t: str) -> bool: + # TC: O(nlogn) + # SC: O(n) + # if sorted(list(s)) == sorted(list(t)): + # return True + # else: + # return False + + chars = dict() + + if len(s) != len(t): + return False + + for c in s: + chars[c] = chars.get(c, 0) + 1 + + for c in t: + if c not in chars: + return False + chars[c] -= 1 + if chars[c] == 0: + chars.pop(c) + + return True + +if __name__ == '__main__': + print(isAnagram('ab', 'a')) From a69cdb9dcde59d068e61005accc03b90e36fdfe1 Mon Sep 17 00:00:00 2001 From: hyh Date: Wed, 19 Nov 2025 23:34:47 +0900 Subject: [PATCH 2/4] dp --- climbing-stairs/deepInTheWoodz.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 climbing-stairs/deepInTheWoodz.py diff --git a/climbing-stairs/deepInTheWoodz.py b/climbing-stairs/deepInTheWoodz.py new file mode 100644 index 0000000000..dd4fd5e603 --- /dev/null +++ b/climbing-stairs/deepInTheWoodz.py @@ -0,0 +1,11 @@ +class Solution: + def climbStairs(self, n: int) -> int: + dp = [0] * (n+2) + dp[1] = 1 + dp[2] = 2 + + for i in range(3, n+2): + dp[i] = dp[i-1] + dp[i-2] + + return dp[n] + \ No newline at end of file From 6f4f48c7581360683516b8e3af3a4566ae8e46c4 Mon Sep 17 00:00:00 2001 From: hyh Date: Wed, 19 Nov 2025 23:38:19 +0900 Subject: [PATCH 3/4] newline add --- climbing-stairs/deepInTheWoodz.py | 1 - 1 file changed, 1 deletion(-) diff --git a/climbing-stairs/deepInTheWoodz.py b/climbing-stairs/deepInTheWoodz.py index dd4fd5e603..f846edfedb 100644 --- a/climbing-stairs/deepInTheWoodz.py +++ b/climbing-stairs/deepInTheWoodz.py @@ -8,4 +8,3 @@ def climbStairs(self, n: int) -> int: dp[i] = dp[i-1] + dp[i-2] return dp[n] - \ No newline at end of file From 9b9e9b2d16376b38328038a1138d4723b4284e03 Mon Sep 17 00:00:00 2001 From: hyh Date: Wed, 19 Nov 2025 23:41:00 +0900 Subject: [PATCH 4/4] tc sc add --- climbing-stairs/deepInTheWoodz.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/climbing-stairs/deepInTheWoodz.py b/climbing-stairs/deepInTheWoodz.py index f846edfedb..0eeb99758a 100644 --- a/climbing-stairs/deepInTheWoodz.py +++ b/climbing-stairs/deepInTheWoodz.py @@ -1,3 +1,5 @@ +# TC: O(1) +# SC: O(1) class Solution: def climbStairs(self, n: int) -> int: dp = [0] * (n+2)