From 1739ed363774a614e1ef76a3591dee1ca6faaeb7 Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Sun, 30 Nov 2025 19:55:45 -0800 Subject: [PATCH 1/8] adding merge two sorted list --- merge-two-sorted-lists/daiyongg-kim.py | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 merge-two-sorted-lists/daiyongg-kim.py diff --git a/merge-two-sorted-lists/daiyongg-kim.py b/merge-two-sorted-lists/daiyongg-kim.py new file mode 100644 index 0000000000..725d88d5ef --- /dev/null +++ b/merge-two-sorted-lists/daiyongg-kim.py @@ -0,0 +1,38 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: + if list1 is None: + return list2 + if list2 is None: + return list1 + + if list1.val < list2.val: + list1.next = self.mergeTwoLists(list1.next, list2) + return list1 + else: + list2.next = self.mergeTwoLists(list1, list2.next) + return list2 + +# class Solution: +# def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: +# result = ListNode(-1) +# dummy = result +# while list1 and list2: +# if list1.val < list2.val: +# dummy.next = list1 +# list1 = list1.next +# else: +# dummy.next = list2 +# list2 = list2.next +# dummy = dummy.next + +# if list1: +# dummy.next = list1 +# else: +# dummy.next = list2 + +# return result.next \ No newline at end of file From 78ae78152f28e334c14592449fe831cc38f016de Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Sun, 30 Nov 2025 20:25:21 -0800 Subject: [PATCH 2/8] adding find minimum in rotated sorted array --- .../daiyongg-kim.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/daiyongg-kim.py diff --git a/find-minimum-in-rotated-sorted-array/daiyongg-kim.py b/find-minimum-in-rotated-sorted-array/daiyongg-kim.py new file mode 100644 index 0000000000..110de379e0 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/daiyongg-kim.py @@ -0,0 +1,14 @@ +class Solution: + def findMin(self, nums: List[int]) -> int: + #constraint complexity: O(log n) + left = 0 + right = len(nums) - 1 + + while left < right: + mid = (left + right) // 2 + + if nums[mid] < nums[right]: + right = mid + else: + left = mid + 1 + return nums[left] From b2fcef717a157001ce8f59afc01e408e534bf1b0 Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Mon, 1 Dec 2025 07:02:24 -0800 Subject: [PATCH 3/8] revies inline --- merge-two-sorted-lists/daiyongg-kim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/merge-two-sorted-lists/daiyongg-kim.py b/merge-two-sorted-lists/daiyongg-kim.py index 725d88d5ef..aacc307de7 100644 --- a/merge-two-sorted-lists/daiyongg-kim.py +++ b/merge-two-sorted-lists/daiyongg-kim.py @@ -35,4 +35,4 @@ def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> # else: # dummy.next = list2 -# return result.next \ No newline at end of file +# return result.next From 8ca556220df4ae86701af16e42f8db00a00ea53f Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Mon, 1 Dec 2025 21:26:23 -0800 Subject: [PATCH 4/8] adding word search --- word-search/daiyongg-kim.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 word-search/daiyongg-kim.py diff --git a/word-search/daiyongg-kim.py b/word-search/daiyongg-kim.py new file mode 100644 index 0000000000..37428225ea --- /dev/null +++ b/word-search/daiyongg-kim.py @@ -0,0 +1,28 @@ +class Solution: + + def exist(self, board: List[List[str]], word: str) -> bool: + row = len(board) + col = len(board[0]) + + def dfs(i: int, j: int, k: int): + if k == len(word): + return True + + if i < 0 or i >= row or j < 0 or j >= col or board[i][j] != word[k]: + return False + + current = board[i][j] + board[i][j] = '' + + if dfs(i-1, j, k+1) or dfs(i+1, j, k+1) or dfs(i, j-1, k+1) or dfs(i, j+1, k+1): + return True + + board[i][j] = current + return False + + for i in range(row): + for j in range(col): + if dfs(i, j, 0): + return True + + return False From a7da2bdf8105bd6954e80936250c7df3950e3bc1 Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Mon, 1 Dec 2025 23:03:37 -0800 Subject: [PATCH 5/8] adding max depth of binary tree --- maximum-depth-of-binary-tree/daiyongg-kim.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 maximum-depth-of-binary-tree/daiyongg-kim.py diff --git a/maximum-depth-of-binary-tree/daiyongg-kim.py b/maximum-depth-of-binary-tree/daiyongg-kim.py new file mode 100644 index 0000000000..4ccbaf63b0 --- /dev/null +++ b/maximum-depth-of-binary-tree/daiyongg-kim.py @@ -0,0 +1,11 @@ +class Solution: + + def maxDepth(self, root: Optional[TreeNode]) -> int: + + if not root: + return 0 + + left_depth = self.maxDepth(root.left) + right_depth = self.maxDepth(root.right) + + return max(left_depth, right_depth) + 1 From 5cb3d981b74d5755e0cca20426288c0985cca823 Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Tue, 2 Dec 2025 09:33:30 -0800 Subject: [PATCH 6/8] update the maxdepth using pq --- maximum-depth-of-binary-tree/daiyongg-kim.py | 25 ++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/maximum-depth-of-binary-tree/daiyongg-kim.py b/maximum-depth-of-binary-tree/daiyongg-kim.py index 4ccbaf63b0..cf354e60f3 100644 --- a/maximum-depth-of-binary-tree/daiyongg-kim.py +++ b/maximum-depth-of-binary-tree/daiyongg-kim.py @@ -1,11 +1,28 @@ class Solution: def maxDepth(self, root: Optional[TreeNode]) -> int: - if not root: return 0 + queue = deque([root]) + print(queue) + depth = 0 + + while queue: + depth += 1 + print(len(queue)) + for _ in range(len(queue)): + node = queue.popleft() + if node.left: + queue.append(node.left) + if node.right: + queue.append(node.right) + return depth + + +# if not root: +# return 0 - left_depth = self.maxDepth(root.left) - right_depth = self.maxDepth(root.right) +# left_depth = self.maxDepth(root.left) +# right_depth = self.maxDepth(root.right) - return max(left_depth, right_depth) + 1 +# return max(left_depth, right_depth) + 1 From bc801a8cc2bd34225d728c3b2c315746f0b5c2c9 Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Tue, 2 Dec 2025 09:50:17 -0800 Subject: [PATCH 7/8] remove print --- maximum-depth-of-binary-tree/daiyongg-kim.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maximum-depth-of-binary-tree/daiyongg-kim.py b/maximum-depth-of-binary-tree/daiyongg-kim.py index cf354e60f3..c31ce33f1c 100644 --- a/maximum-depth-of-binary-tree/daiyongg-kim.py +++ b/maximum-depth-of-binary-tree/daiyongg-kim.py @@ -4,7 +4,6 @@ def maxDepth(self, root: Optional[TreeNode]) -> int: if not root: return 0 queue = deque([root]) - print(queue) depth = 0 while queue: From be7f1dfd1bb0a2355755217548fed177a90ff96f Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Thu, 4 Dec 2025 07:41:32 -0800 Subject: [PATCH 8/8] adding coin changes --- coin-change/daiyongg-kim.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 coin-change/daiyongg-kim.py diff --git a/coin-change/daiyongg-kim.py b/coin-change/daiyongg-kim.py new file mode 100644 index 0000000000..f1b51a9004 --- /dev/null +++ b/coin-change/daiyongg-kim.py @@ -0,0 +1,26 @@ +class Solution: + def coinChange(self, coins: List[int], amount: int) -> int: + if amount == 0: + return 0 + + level = [0] + visited = {0} + count = 0 + + while level: + count += 1 + next_level = [] + + for current_amount in level: + for coin in coins: + new_amount = current_amount + coin + + if new_amount == amount: + return count + + if new_amount < amount and new_amount not in visited: + visited.add(new_amount) + next_level.append(new_amount) + level = next_level + + return -1