From b9fedda1aa25b1a170b884f89acb6700bc858d73 Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Sun, 28 Jun 2026 15:55:10 +0200 Subject: [PATCH 1/6] solve valid anagram --- valid-anagram/njngwn.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 valid-anagram/njngwn.py diff --git a/valid-anagram/njngwn.py b/valid-anagram/njngwn.py new file mode 100644 index 0000000000..da47ffffe5 --- /dev/null +++ b/valid-anagram/njngwn.py @@ -0,0 +1,7 @@ +from collections import Counter + +class Solution: + # Time Complexity: O(n), n: max(len(s), len(t)) + # Space Complexity: O(k), k: number of letters + def isAnagram(self, s: str, t: str) -> bool: + return Counter(s) == Counter(t) From b9449de5dd6bd3f51396766844f037dd1141f02b Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Tue, 30 Jun 2026 15:54:38 +0200 Subject: [PATCH 2/6] solve climbing stairs --- climbing-stairs/njngwn.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 climbing-stairs/njngwn.py diff --git a/climbing-stairs/njngwn.py b/climbing-stairs/njngwn.py new file mode 100644 index 0000000000..1d2fb959cb --- /dev/null +++ b/climbing-stairs/njngwn.py @@ -0,0 +1,12 @@ +class Solution: + # dynamic programming with bottom-up + # Time Complexity: O(n) + # Space Complexity: O(1) + def climbStairs(self, n: int) -> int: + if n <= 2: return n + prev1, prev2 = 2, 1 + + for i in range(3, n+1): + prev1, prev2 = prev2 + prev1, prev1 + + return prev1 From 7c6c46412326a84f94a4bff1fc34736dc357d08f Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Sat, 25 Jul 2026 11:25:41 +0200 Subject: [PATCH 3/6] solve best time to buy and sell stock --- best-time-to-buy-and-sell-stock/njngwn.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/njngwn.py diff --git a/best-time-to-buy-and-sell-stock/njngwn.py b/best-time-to-buy-and-sell-stock/njngwn.py new file mode 100644 index 0000000000..0a07f6bfb7 --- /dev/null +++ b/best-time-to-buy-and-sell-stock/njngwn.py @@ -0,0 +1,12 @@ +class Solution: + # Time Complexity: O(n), n: len(prices) + # Space Complexity: O(1) + def maxProfit(self, prices: List[int]) -> int: + min_price = prices[0] + profit = 0 + + for i in range(1, len(prices)): + min_price = min(min_price, prices[i]) + profit = max(profit, prices[i] - min_price) + + return profit From d68a82c6416f288cc2eb45089bfa5fae9f565809 Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Sat, 25 Jul 2026 12:15:17 +0200 Subject: [PATCH 4/6] solve group anagrams --- group-anagrams/njngwn.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 group-anagrams/njngwn.py diff --git a/group-anagrams/njngwn.py b/group-anagrams/njngwn.py new file mode 100644 index 0000000000..087589153a --- /dev/null +++ b/group-anagrams/njngwn.py @@ -0,0 +1,14 @@ +class Solution: + # Time Complexity: O(n), n: len(strs) + # Space Complexity: O(n), n: len(strs) + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + anagram_groups = dict() # key: string in an alphabetical order, values: strings + + for s in strs: + word = ''.join(sorted(s)) + if word in anagram_groups: + anagram_groups[word].extend([s]) + else: + anagram_groups[word] = [s] + + return list(anagram_groups.values()) From 887666fb1e816b028565ca910cf045332a721797 Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Sat, 25 Jul 2026 12:17:02 +0200 Subject: [PATCH 5/6] solve encode and decode strings --- encode-and-decode-strings/njngwn.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 encode-and-decode-strings/njngwn.py diff --git a/encode-and-decode-strings/njngwn.py b/encode-and-decode-strings/njngwn.py new file mode 100644 index 0000000000..1d72058f64 --- /dev/null +++ b/encode-and-decode-strings/njngwn.py @@ -0,0 +1,26 @@ +class Solution: + + def encode(self, strs: List[str]) -> str: + encoded = '' + + for s in strs: + encoded += str(len(s)) + '#' + s + + return encoded + + def decode(self, s: str) -> List[str]: + decoded = [] + + i = 0 + while i < len(s): + j = i # j is a pointer for beginning of string + # find '#' in string + while s[j] != '#': + j += 1 + + length = int(s[i:j]) + word = s[j + 1:j + length + 1] + decoded.append(word) + i = j + length + 1 + + return decoded From 245d8e2c4856a129be336c91c54125ee7ca5cc4b Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Sat, 25 Jul 2026 13:17:44 +0200 Subject: [PATCH 6/6] solve word break --- word-break/njngwn.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 word-break/njngwn.py diff --git a/word-break/njngwn.py b/word-break/njngwn.py new file mode 100644 index 0000000000..f15acb142a --- /dev/null +++ b/word-break/njngwn.py @@ -0,0 +1,16 @@ +from functools import cache + + +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + @cache + def check(cur): + if cur == len(s): + return True + for word in wordDict: + if s[cur: cur + len(word)] == word: + if check(cur + len(word)): + return True + return False + + return check(0)