From 4cd1dc83c8b85e713b41da7b2f107544300310bd Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 2 Jan 2026 16:39:34 -0500 Subject: [PATCH 1/6] 141. Linked List Cycle --- linked-list-cycle/doh6077.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 linked-list-cycle/doh6077.py diff --git a/linked-list-cycle/doh6077.py b/linked-list-cycle/doh6077.py new file mode 100644 index 0000000000..dd1d146324 --- /dev/null +++ b/linked-list-cycle/doh6077.py @@ -0,0 +1,27 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None +''' +# 141. Linked List Cycle + +1. Create an empty list to keep track of visited nodes. +2. Traverse the linked list starting from the head node. + +''' +class Solution: + def hasCycle(self, head: Optional[ListNode]) -> bool: + record = [] + if head == None: + return False + + while head.next: + record.append(head) + if head.next in record: + return True + head = head.next + return False + + + \ No newline at end of file From d3263db1808f3539c70ea868f413d3bbc43cf174 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Sat, 3 Jan 2026 14:04:26 -0500 Subject: [PATCH 2/6] Sum of Two Integers solution --- sum-of-two-integers/doh6077.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 sum-of-two-integers/doh6077.java diff --git a/sum-of-two-integers/doh6077.java b/sum-of-two-integers/doh6077.java new file mode 100644 index 0000000000..b480589755 --- /dev/null +++ b/sum-of-two-integers/doh6077.java @@ -0,0 +1,11 @@ +class Solution { + public int getSum(int a, int b) { + while (b != 0) { + int tmp = (a & b) << 1; + a = a ^ b; + b = tmp; + } + return a; + + } +} From 923c21bc0d9bfae82450da0b95fe3391a832bf7f Mon Sep 17 00:00:00 2001 From: doh6077 Date: Wed, 7 Jan 2026 13:17:39 -0500 Subject: [PATCH 3/6] 152. Maximum Product Subarray Solution --- linked-list-cycle/doh6077.py | 3 --- maximum-product-subarray/doh6077.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 maximum-product-subarray/doh6077.py diff --git a/linked-list-cycle/doh6077.py b/linked-list-cycle/doh6077.py index dd1d146324..8637a49981 100644 --- a/linked-list-cycle/doh6077.py +++ b/linked-list-cycle/doh6077.py @@ -22,6 +22,3 @@ def hasCycle(self, head: Optional[ListNode]) -> bool: return True head = head.next return False - - - \ No newline at end of file diff --git a/maximum-product-subarray/doh6077.py b/maximum-product-subarray/doh6077.py new file mode 100644 index 0000000000..3ab7b29241 --- /dev/null +++ b/maximum-product-subarray/doh6077.py @@ -0,0 +1,26 @@ +#152. Maximum Product Subarray + +# https://leetcode.com/problems/maximum-product-subarray/ +# + + +# Three cases to consider +# negative number +# positive number +# zero - we reset the curMin and curMax to 1 ( neutral element for multiplication) +class Solution: + def maxProduct(self, nums: List[int]) -> int: + res = max(nums) + + curMin, curMax = 1, 1 + + for num in nums: + if num == 0 : + curMin, curMax = 1, 1 + continue + temp = curMax * num + curMax = max(curMax * num, curMin * num, num) + curMin = min(curMin * num, temp, num) + res = max(res, curMax) + return res + \ No newline at end of file From 5763390b0161bc6d41ba6466f793e8f6d84d16d1 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Wed, 7 Jan 2026 13:19:26 -0500 Subject: [PATCH 4/6] =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maximum-product-subarray/doh6077.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maximum-product-subarray/doh6077.py b/maximum-product-subarray/doh6077.py index 3ab7b29241..b6268730d4 100644 --- a/maximum-product-subarray/doh6077.py +++ b/maximum-product-subarray/doh6077.py @@ -23,4 +23,3 @@ def maxProduct(self, nums: List[int]) -> int: curMin = min(curMin * num, temp, num) res = max(res, curMax) return res - \ No newline at end of file From 272d8fb637a2a33aa9e1f4dd9774ce5c9c16b70d Mon Sep 17 00:00:00 2001 From: doh6077 Date: Thu, 8 Jan 2026 17:02:08 -0500 Subject: [PATCH 5/6] Solution Pacific Atlantic Water Flow --- pacific-atlantic-water-flow/doh6077.py | 92 ++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 pacific-atlantic-water-flow/doh6077.py diff --git a/pacific-atlantic-water-flow/doh6077.py b/pacific-atlantic-water-flow/doh6077.py new file mode 100644 index 0000000000..a598c260ad --- /dev/null +++ b/pacific-atlantic-water-flow/doh6077.py @@ -0,0 +1,92 @@ +# # 417. Pacific Atlantic Water Flow +from collections import deque + +class Solution: + # Time Complexity O(m*n) + + def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]: + #Two BFS + # intersection of two hash sets + p_que = deque() + p_seen = set() + + a_que = deque() + a_seen = set() + + m, n = len(heights), len(heights[0]) + for j in range(n): + p_que.append((0,j)) + p_seen.add((0,j)) + + for i in range(1,m): + p_que.append((i,0)) + p_seen.add((i,0)) + + for i in range(m): + a_que.append((i, n-1)) + a_seen.add((i, n-1)) + + for j in range(n-1): + a_que.append((m-1,j)) + a_seen.add((m-1,j)) + + def get_coords(que,seen): + coords = set() + while que: + i, j = que.popleft() + coords.add((i,j)) + for i_off, j_off in [(0,1), (1,0), (-1,0), (0,-1)]: + r, c = i+i_off, j +j_off + if 0 <= r < m and 0 <= c < n and heights[r][c] >= heights[i][j] and (r,c) not in seen: + seen.add((r,c)) + que.append((r,c)) + return coords + + p_coords = get_coords(p_que, p_seen) + a_coords = get_coords(a_que, a_seen) + return list(p_coords.intersection(a_coords)) + +# # First Draft + +# class Solution: +# def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]: + +# # first Attempt +# self.res = [] +# self.pacific = [] +# self.atlantic = [] +# # Brute Force +# # DFS - every single position +# # 1. Pacific Ocean ( in a row: the left side is less than the number) or ( in a column, the previous value is less than the number) +# # 2. Atlantic Ocean ( in a row: the right side is less than the number) or (in a column, the next values are less than the number) +# # 3. if the number satisfies both then we add the coordinates of the number to the result + +# def dfs(list_check): +# find_max = max(list_check) +# max_index = list_check.index(find_max) + + +# # pacific +# if max_index != 0: +# check_paci = [0, max_index] +# self.pacific.append(check_paci) +# if max_index != len(list_check): +# check_atlantic = [max_index, 0] +# self.atlantic.append(check_atlantic) + +# if len(heights) == 1: +# return [[0,0]] + +# for i, row in enumerate(heights): + +# dfs(row) + +# columns = list(zip(*heights)) # each column becomes a tuple +# for c, col in enumerate(columns): +# dfs(col) +# print(self.pacific) +# print(self.atlantic) + +# return self.res + + \ No newline at end of file From b8171a1a795c3d781bd02df468470155dc937296 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Thu, 8 Jan 2026 17:06:46 -0500 Subject: [PATCH 6/6] =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pacific-atlantic-water-flow/doh6077.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pacific-atlantic-water-flow/doh6077.py b/pacific-atlantic-water-flow/doh6077.py index a598c260ad..aa99af4439 100644 --- a/pacific-atlantic-water-flow/doh6077.py +++ b/pacific-atlantic-water-flow/doh6077.py @@ -88,5 +88,3 @@ def get_coords(que,seen): # print(self.atlantic) # return self.res - - \ No newline at end of file