diff --git a/maximum-depth-of-binary-tree/chordpli.py b/maximum-depth-of-binary-tree/chordpli.py new file mode 100644 index 000000000..15c28b3b0 --- /dev/null +++ b/maximum-depth-of-binary-tree/chordpli.py @@ -0,0 +1,9 @@ +class Solution: + def maxDepth(self, root: Optional[TreeNode]) -> int: + if not root: + return 0 + + right = self.maxDepth(root.right) + left = self.maxDepth(root.left) + + return max(right, left) + 1 diff --git a/merge-two-sorted-lists/chordpli.py b/merge-two-sorted-lists/chordpli.py new file mode 100644 index 000000000..684b690a8 --- /dev/null +++ b/merge-two-sorted-lists/chordpli.py @@ -0,0 +1,29 @@ +# 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: + return list2 + + if not list2: + return list1 + + merge_node: ListNode = ListNode() + current = merge_node + + while list1 and list2: + if list1.val < list2.val: + current.next = list1 + list1 = list1.next + else: + current.next = list2 + list2 = list2.next + + current = current.next + + current.next = list1 or list2 + return merge_node.next