diff --git a/maximum-depth-of-binary-tree/doh6077.py b/maximum-depth-of-binary-tree/doh6077.py new file mode 100644 index 0000000000..3b05278afd --- /dev/null +++ b/maximum-depth-of-binary-tree/doh6077.py @@ -0,0 +1,11 @@ + +# Time: O(n) +# 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) 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