From ae677565e1333325e41402d7d5d287c210555677 Mon Sep 17 00:00:00 2001 From: sangyoon Date: Sat, 6 Dec 2025 16:41:51 +0900 Subject: [PATCH 1/2] Week 4: merge-two-sorted-lists solution --- merge-two-sorted-lists/mandel-17.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 merge-two-sorted-lists/mandel-17.py diff --git a/merge-two-sorted-lists/mandel-17.py b/merge-two-sorted-lists/mandel-17.py new file mode 100644 index 0000000000..828864ad45 --- /dev/null +++ b/merge-two-sorted-lists/mandel-17.py @@ -0,0 +1,16 @@ +from typing import Optional + +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 (not list1) or (list2 and list1.val > list2.val): + list1, list2 = list2, list1 + if list1: + list1.next = self.mergeTwoLists(list1.next, list2) + + return list1 + From 6a1406568548d4506ee85a967a1cc9a4f2d41486 Mon Sep 17 00:00:00 2001 From: sangyoon Date: Sat, 6 Dec 2025 16:42:29 +0900 Subject: [PATCH 2/2] Week 4: maximum-depth-of-binary-tree solution --- maximum-depth-of-binary-tree/mandel-17.py | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 maximum-depth-of-binary-tree/mandel-17.py diff --git a/maximum-depth-of-binary-tree/mandel-17.py b/maximum-depth-of-binary-tree/mandel-17.py new file mode 100644 index 0000000000..a15a029561 --- /dev/null +++ b/maximum-depth-of-binary-tree/mandel-17.py @@ -0,0 +1,26 @@ +import collections +from typing import Optional + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + +class Solution: + def maxDepth(self, root: Optional[TreeNode]) -> int: + if root is None: + return 0 + queue = collections.deque([root]) + depth = 0 + + while queue: + depth += 1 + for _ in range(len(queue)): + current_root = queue.popleft() + if current_root.left: + queue.append(current_root.left) + if current_root.right: + queue.append(current_root.right) + return depth +