From 4b9eb36970157e2f698503d06a97a2dd674f8d0a Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 12 Aug 2026 22:35:15 +0900 Subject: [PATCH 1/7] reverse bits solution --- reverse-bits/yuseok89.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 reverse-bits/yuseok89.py diff --git a/reverse-bits/yuseok89.py b/reverse-bits/yuseok89.py new file mode 100644 index 0000000000..c717168ef0 --- /dev/null +++ b/reverse-bits/yuseok89.py @@ -0,0 +1,13 @@ +# TC: O(K) +# SC: O(1) +class Solution: + def reverseBits(self, n: int) -> int: + ans = 0 + + for _ in range(32): + ans *= 2 + ans += n % 2 + n //= 2 + + return ans + From 00826e86d541a7ba97c8bcf592ed5fa2c5175d18 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 12 Aug 2026 22:43:35 +0900 Subject: [PATCH 2/7] longest repeating character replacement solution --- .../yuseok89.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 longest-repeating-character-replacement/yuseok89.py diff --git a/longest-repeating-character-replacement/yuseok89.py b/longest-repeating-character-replacement/yuseok89.py new file mode 100644 index 0000000000..77b82b3cad --- /dev/null +++ b/longest-repeating-character-replacement/yuseok89.py @@ -0,0 +1,27 @@ +# TC: O(N) +# SC: O(K) +class Solution: + def characterReplacement(self, s: str, k: int) -> int: + + l = 0 + cnt = defaultdict(int) + m, ans = 0, 0 + + for r in range(len(s)): + c = s[r] + cnt[c] += 1 + + m = max(m, cnt[c]) + + while m + k < r - l + 1: + c = s[l] + l += 1 + cnt[c] -= 1 + + if cnt[c] == m - 1: + m = max(cnt.values()) + + ans = max(ans, r - l + 1); + + return ans + From 015ee6c215b7993272ecea4f5730e1251c2942bd Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 12 Aug 2026 22:45:07 +0900 Subject: [PATCH 3/7] clone graph solution --- clone-graph/yuseok89.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 clone-graph/yuseok89.py diff --git a/clone-graph/yuseok89.py b/clone-graph/yuseok89.py new file mode 100644 index 0000000000..c29a9049fc --- /dev/null +++ b/clone-graph/yuseok89.py @@ -0,0 +1,37 @@ +# TC: O(N) +# SC: O(N) +""" +# Definition for a Node. +class Node: + def __init__(self, val = 0, neighbors = None): + self.val = val + self.neighbors = neighbors if neighbors is not None else [] +""" + +from typing import Optional +class Solution: + def cloneGraph(self, node: Optional['Node']) -> Optional['Node']: + + visited = {} + + def rec(node: Optional['Node']) -> Optional['Node']: + + if not node: + return None + + if node.val in visited: + return visited[node.val] + + return_val = Node(node.val) + visited[node.val] = return_val + + for neighbor in node.neighbors: + cloned = rec(neighbor) + + if cloned: + return_val.neighbors.append(cloned) + + return return_val + + return rec(node) + From 887a9ffc66dd4ed7dd4440e8ef7b5b6d2ee517ab Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 12 Aug 2026 22:46:50 +0900 Subject: [PATCH 4/7] palindromic solution --- palindromic-substrings/yuseok89.py | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 palindromic-substrings/yuseok89.py diff --git a/palindromic-substrings/yuseok89.py b/palindromic-substrings/yuseok89.py new file mode 100644 index 0000000000..a5d8ad73d5 --- /dev/null +++ b/palindromic-substrings/yuseok89.py @@ -0,0 +1,31 @@ +# TC: O(N^2) +# SC: O(1) +class Solution: + def countSubstrings(self, s: str) -> int: + + ans = 0 + n = len(s) + + for center_idx in range(n): + + idx = 0 + + while 0 <= center_idx - idx and center_idx + idx < n: + if s[center_idx - idx] == s[center_idx + idx]: + ans = ans + 1 + else: + break + + idx += 1 + + idx = 0 + while 0 <= center_idx - idx and center_idx + idx + 1< n: + if s[center_idx - idx] == s[center_idx + idx + 1]: + ans = ans + 1 + else: + break + + idx += 1 + + return ans + From 5ef2d539f7130e524c3fc6d61917d947f0f189c9 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 12 Aug 2026 22:49:27 +0900 Subject: [PATCH 5/7] longest common subsequence solution --- longest-common-subsequence/yuseok89.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 longest-common-subsequence/yuseok89.py diff --git a/longest-common-subsequence/yuseok89.py b/longest-common-subsequence/yuseok89.py new file mode 100644 index 0000000000..c6d741b271 --- /dev/null +++ b/longest-common-subsequence/yuseok89.py @@ -0,0 +1,18 @@ +# TC: O(N*M) +# SC: O(N*M) +class Solution: + def longestCommonSubsequence(self, text1: str, text2: str) -> int: + + n = len(text1) + m = len(text2) + dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)] + + for i in range(n): + for j in range(m): + if text1[i] == text2[j]: + dp[i + 1][j + 1] = dp[i][j] + 1 + else: + dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) + + return dp[n][m] + From 935c0f7066f30ef02399acd7ffc9925d77497c3d Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 14 Aug 2026 23:32:57 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- longest-common-subsequence/yuseok89.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/longest-common-subsequence/yuseok89.py b/longest-common-subsequence/yuseok89.py index c6d741b271..0b694c3563 100644 --- a/longest-common-subsequence/yuseok89.py +++ b/longest-common-subsequence/yuseok89.py @@ -1,18 +1,22 @@ # TC: O(N*M) -# SC: O(N*M) +# SC: O(N) class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: n = len(text1) m = len(text2) - dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)] + dp = [[0 for _ in range(m + 1)] for _ in range(2)] + + cur, prev = 1, 0 for i in range(n): for j in range(m): if text1[i] == text2[j]: - dp[i + 1][j + 1] = dp[i][j] + 1 + dp[cur][j + 1] = dp[prev][j] + 1 else: - dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) + dp[cur][j + 1] = max(dp[prev][j + 1], dp[cur][j]) + + cur, prev = prev, cur - return dp[n][m] + return dp[prev][m] From 9454135c74ef9616c9a2fed747f601ef217a611d Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 14 Aug 2026 23:34:00 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- longest-common-subsequence/yuseok89.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longest-common-subsequence/yuseok89.py b/longest-common-subsequence/yuseok89.py index 0b694c3563..dbe78d900a 100644 --- a/longest-common-subsequence/yuseok89.py +++ b/longest-common-subsequence/yuseok89.py @@ -1,5 +1,5 @@ # TC: O(N*M) -# SC: O(N) +# SC: O(M) class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: