From 41b70c839db7731d2a51eba9e17311b6127e9340 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 19 Aug 2026 23:43:58 +0900 Subject: [PATCH 1/6] linked list cycle solution --- linked-list-cycle/yuseok89.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 linked-list-cycle/yuseok89.py diff --git a/linked-list-cycle/yuseok89.py b/linked-list-cycle/yuseok89.py new file mode 100644 index 0000000000..6d956e6910 --- /dev/null +++ b/linked-list-cycle/yuseok89.py @@ -0,0 +1,22 @@ +# TC: O(N) +# SC: O(1) +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def hasCycle(self, head: Optional[ListNode]) -> bool: + if not head or not head.next: + return False + + slow, fast = head, head.next + while slow != fast: + if not fast or not fast.next: + return False + + slow, fast = slow.next, fast.next.next + + return True + From b88d968fd438c6dd8213f707a4cb6cde3062d0a2 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Thu, 20 Aug 2026 23:07:18 +0900 Subject: [PATCH 2/6] pacific atlantic water flow solution --- pacific-atlantic-water-flow/yuseok89.py | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pacific-atlantic-water-flow/yuseok89.py diff --git a/pacific-atlantic-water-flow/yuseok89.py b/pacific-atlantic-water-flow/yuseok89.py new file mode 100644 index 0000000000..598901b20b --- /dev/null +++ b/pacific-atlantic-water-flow/yuseok89.py @@ -0,0 +1,44 @@ +# TC: O(N*M) +# SC: O(N*M) +class Solution: + def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]: + + n = len(heights) + m = len(heights[0]) + + dirs = [[0, 1], [0, -1], [1, 0], [-1, 0]] + + def dfs(row, col, check): + check[row][col] = True + + for dir in dirs: + new_row = row + dir[0] + new_col = col + dir[1] + + if 0 <= new_row < n and 0 <= new_col < m and not check[new_row][new_col] and heights[row][col] <= heights[new_row][new_col]: + dfs(new_row, new_col, check) + + pac_check = [[False for _ in range(m)] for _ in range(n)] + atl_check = [[False for _ in range(m)] for _ in range(n)] + + for row in range(1, n): + dfs(row, 0, pac_check) + + for col in range(m): + dfs(0, col, pac_check) + + for row in range(n - 1): + dfs(row, m - 1, atl_check) + + for col in range(m): + dfs(n - 1, col, atl_check) + + ans = [] + + for row in range(n): + for col in range(m): + if pac_check[row][col] and atl_check[row][col]: + ans.append([row, col]) + + return ans + From f0817b43ea6d8741ab879da6779fd16f62c08e59 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 21 Aug 2026 22:37:20 +0900 Subject: [PATCH 3/6] maximum product subarray solution --- maximum-product-subarray/yuseok89.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 maximum-product-subarray/yuseok89.py diff --git a/maximum-product-subarray/yuseok89.py b/maximum-product-subarray/yuseok89.py new file mode 100644 index 0000000000..bfb3cbb99f --- /dev/null +++ b/maximum-product-subarray/yuseok89.py @@ -0,0 +1,17 @@ +# TC: O(N) +# SC: O(1) +class Solution: + def maxProduct(self, nums: List[int]) -> int: + + ans = nums[0] + max_val, min_val = 1, 1 + + for num in nums: + temp = max_val * num + max_val = max(temp, min_val * num, num) + min_val = min(temp, min_val * num, num) + + ans = max(ans, max_val) + + return ans + From 79b95629da081a965d54bf6909990b4b518e3841 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 21 Aug 2026 22:53:04 +0900 Subject: [PATCH 4/6] sum of two integers solution --- sum-of-two-integers/yuseok89.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sum-of-two-integers/yuseok89.py diff --git a/sum-of-two-integers/yuseok89.py b/sum-of-two-integers/yuseok89.py new file mode 100644 index 0000000000..9052b32c29 --- /dev/null +++ b/sum-of-two-integers/yuseok89.py @@ -0,0 +1,19 @@ +# TC: O(12) +# SC: O(1) +class Solution: + def getSum(self, a: int, b: int) -> int: + MASK = 0b111111111111 + + a = a & MASK + b = b & MASK + + while b != 0: + c = (a & b) << 1 + a = a ^ b + b = c & MASK + + if a > (MASK >> 1): + a = ~(a ^ MASK) + + return a + From 91bd82fa70b55492aa498184812b0cb114739324 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 21 Aug 2026 23:58:24 +0900 Subject: [PATCH 5/6] minimum window subarray solution --- minimum-window-substring/yuseok89.py | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 minimum-window-substring/yuseok89.py diff --git a/minimum-window-substring/yuseok89.py b/minimum-window-substring/yuseok89.py new file mode 100644 index 0000000000..728a516eb9 --- /dev/null +++ b/minimum-window-substring/yuseok89.py @@ -0,0 +1,45 @@ +# TC: O(N) +# SC: O(N) +class Solution: + def minWindow(self, s: str, t: str) -> str: + + len_s = len(s) + len_t = len(t) + + min_len = len_s + 1 + ans_start_idx = -1 + total_cnt = 0 + + t_cnt_dict = Counter(t) + cnt_dict = defaultdict(int) + + l, r = 0, 0 + + while r < len_s: + + r_c = s[r] + + if cnt_dict[r_c] < t_cnt_dict.get(r_c, 0): + total_cnt += 1 + + cnt_dict[r_c] += 1 + r += 1 + + while total_cnt == len_t: + if min_len > r - l: + min_len = r - l + ans_start_idx = l + + l_c = s[l] + + if cnt_dict[l_c] <= t_cnt_dict[l_c]: + total_cnt -= 1 + + cnt_dict[l_c] -= 1 + l += 1 + + if ans_start_idx == -1: + return '' + + return s[ans_start_idx:ans_start_idx + min_len] + From dc2b135951a912d215eeedeeaea489210c9f35ae Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Sat, 22 Aug 2026 00:05:57 +0900 Subject: [PATCH 6/6] =?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 --- linked-list-cycle/yuseok89.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linked-list-cycle/yuseok89.py b/linked-list-cycle/yuseok89.py index 6d956e6910..6cb4c47072 100644 --- a/linked-list-cycle/yuseok89.py +++ b/linked-list-cycle/yuseok89.py @@ -8,11 +8,11 @@ class Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: - if not head or not head.next: + if not head: return False slow, fast = head, head.next - while slow != fast: + while slow is not fast: if not fast or not fast.next: return False