File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
maximum-depth-of-binary-tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ # Time: O(n)
3+ # Maximum Depth of Binary Tree
4+ class Solution :
5+ def maxDepth (self , root : Optional [TreeNode ]) -> int :
6+ if not root :
7+ return 0 # base case
8+ left = self .maxDepth (root .left )
9+ right = self .maxDepth (root .right )
10+
11+ return 1 + max (left , right )
Original file line number Diff line number Diff line change 1+
2+ # 21. Merge Two Sorted Lists
3+
4+ class Solution :
5+ def mergeTwoLists (self , list1 : Optional [ListNode ], list2 : Optional [ListNode ]) -> Optional [ListNode ]:
6+ tempNode = ListNode ()
7+ node = tempNode
8+ while list1 and list2 :
9+ if list1 .val < list2 .val :
10+ node .next = list1
11+ list1 = list1 .next
12+ else :
13+ node .next = list2
14+ list2 = list2 .next
15+ node = node .next
16+ node .next = list1 or list2
17+ return tempNode .next
You can’t perform that action at this time.
0 commit comments