Skip to content

Commit 1d57850

Browse files
authored
Merge pull request #2140 from doh6077/main
[doh6077] WEEK 04 solutions
2 parents 8ddeaea + e793352 commit 1d57850

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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)

merge-two-sorted-lists/doh6077.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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

0 commit comments

Comments
 (0)