From 161edcca4973e48bcb462274b5a2ae07b162fcdd Mon Sep 17 00:00:00 2001 From: doh6077 Date: Thu, 4 Dec 2025 13:07:32 -0500 Subject: [PATCH 1/4] 21. Merge Two Sorted Lists solution --- merge-two-sorted-lists/doh6077.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 merge-two-sorted-lists/doh6077.py diff --git a/merge-two-sorted-lists/doh6077.py b/merge-two-sorted-lists/doh6077.py new file mode 100644 index 0000000000..ba96bc5db4 --- /dev/null +++ b/merge-two-sorted-lists/doh6077.py @@ -0,0 +1,17 @@ + +# 21. Merge Two Sorted Lists + +class Solution: + def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: + tempNode = ListNode() + node = tempNode + while list1 and list2: + if list1.val < list2.val: + node.next = list1 + list1 = list1.next + else: + node.next = list2 + list2 = list2.next + node = node.next + node.next = list1 or list2 + return tempNode.next From dd9a296a35079733e18c5da8ede25b22b82ce887 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Thu, 4 Dec 2025 17:09:13 -0500 Subject: [PATCH 2/4] Maximum Depth of Binary Tree solution --- maximum-depth-of-binary-tree/doh6077.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 maximum-depth-of-binary-tree/doh6077.py diff --git a/maximum-depth-of-binary-tree/doh6077.py b/maximum-depth-of-binary-tree/doh6077.py new file mode 100644 index 0000000000..f81231d244 --- /dev/null +++ b/maximum-depth-of-binary-tree/doh6077.py @@ -0,0 +1,13 @@ + +# Maximum Depth of Binary Tree +class Solution: + def maxDepth(self, root: Optional[TreeNode]) -> int: + if not root: + return 0 # base case + left = self.maxDepth(root.left) + right = self.maxDepth(root.right) + + return 1 + max(left, right) + + # Time: O(n) + \ No newline at end of file From 457b3949a8bb1310cad45714c0c7b28ff41ae798 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Thu, 4 Dec 2025 17:10:36 -0500 Subject: [PATCH 3/4] add end line --- maximum-depth-of-binary-tree/doh6077.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/maximum-depth-of-binary-tree/doh6077.py b/maximum-depth-of-binary-tree/doh6077.py index f81231d244..b149d05364 100644 --- a/maximum-depth-of-binary-tree/doh6077.py +++ b/maximum-depth-of-binary-tree/doh6077.py @@ -1,4 +1,5 @@ +# Time: O(n) # Maximum Depth of Binary Tree class Solution: def maxDepth(self, root: Optional[TreeNode]) -> int: @@ -8,6 +9,4 @@ def maxDepth(self, root: Optional[TreeNode]) -> int: right = self.maxDepth(root.right) return 1 + max(left, right) - - # Time: O(n) \ No newline at end of file From e7933529852151b8d31f9d36cf409fa7b509297d Mon Sep 17 00:00:00 2001 From: doh6077 Date: Thu, 4 Dec 2025 17:13:34 -0500 Subject: [PATCH 4/4] add end line --- maximum-depth-of-binary-tree/doh6077.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maximum-depth-of-binary-tree/doh6077.py b/maximum-depth-of-binary-tree/doh6077.py index b149d05364..3b05278afd 100644 --- a/maximum-depth-of-binary-tree/doh6077.py +++ b/maximum-depth-of-binary-tree/doh6077.py @@ -9,4 +9,3 @@ def maxDepth(self, root: Optional[TreeNode]) -> int: right = self.maxDepth(root.right) return 1 + max(left, right) - \ No newline at end of file