From 7353b8aaacde9f1bd0dc6256043693a1987b4ff4 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Mon, 13 Jul 2026 18:32:21 +0900 Subject: [PATCH 1/3] merge two sorted lists solution --- merge-two-sorted-lists/dolphinflow86.py | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 merge-two-sorted-lists/dolphinflow86.py diff --git a/merge-two-sorted-lists/dolphinflow86.py b/merge-two-sorted-lists/dolphinflow86.py new file mode 100644 index 0000000000..497cbfd7db --- /dev/null +++ b/merge-two-sorted-lists/dolphinflow86.py @@ -0,0 +1,27 @@ +# 1) Use a dummy node and connect the smaller node to the merged list while iterating through both lists. +# TC: O(N + M) where N is the length of list1 and M is the length of list2. +# SC: O(1) +# +# 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]: + dummy = ListNode() + curr = dummy + + while list1 and list2: + if list1.val < list2.val: + curr.next = list1 + list1 = list1.next + else: + curr.next = list2 + list2 = list2.next + curr = curr.next + + curr.next = list1 if list1 else list2 + + return dummy.next From d3c61fa56805814ec6b9947d5ee04ac276be856f Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Tue, 14 Jul 2026 20:55:33 +0900 Subject: [PATCH 2/3] maximum depth of binary tree solution --- maximum-depth-of-binary-tree/dolphinflow86.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 maximum-depth-of-binary-tree/dolphinflow86.py diff --git a/maximum-depth-of-binary-tree/dolphinflow86.py b/maximum-depth-of-binary-tree/dolphinflow86.py new file mode 100644 index 0000000000..cfd6ae7d55 --- /dev/null +++ b/maximum-depth-of-binary-tree/dolphinflow86.py @@ -0,0 +1,20 @@ +# 1) Use DFS to traverse down to the leaf node. Keep track of depth and return each node's maximum depth of each subtree to the parent node. +# TC: O(N) where N is the number of node in the binary tree +# SC: O(H) where H is the height of the binary tree +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def dfs(self, node: Optional[TreeNode], depth: int) -> int: + if not node: + return depth + + left = self.dfs(node.left, depth + 1) + right = self.dfs(node.right, depth + 1) + return max(left, right) + + def maxDepth(self, root: Optional[TreeNode]) -> int: + return self.dfs(root, 0) From 86f27d280245f734efddf3f143da545217b7060f Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Thu, 16 Jul 2026 18:07:39 +0900 Subject: [PATCH 3/3] find minimum in rotated sorted array solution --- .../dolphinflow86.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 find-minimum-in-rotated-sorted-array/dolphinflow86.py diff --git a/find-minimum-in-rotated-sorted-array/dolphinflow86.py b/find-minimum-in-rotated-sorted-array/dolphinflow86.py new file mode 100644 index 0000000000..c34911d340 --- /dev/null +++ b/find-minimum-in-rotated-sorted-array/dolphinflow86.py @@ -0,0 +1,20 @@ +# 1) Use binary search to halves to search range. Each iteration, +# compare with nums[pivot] and nums[right] to see which side has a smaller range. +# Firstly I compare nums[left] with nums[right] so I got the wrong results but end up with the right solution. +# TC: O(logN) where N is the length of the nums array +# SC: O(1) + +class Solution: + def findMin(self, nums: List[int]) -> int: + n = len(nums) + left = 0 + right = n-1 + + while left < right: + pivot = left + (right - left) // 2 + if nums[pivot] < nums[right]: + right = pivot + else: + left = pivot + 1 + + return nums[right]