Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions maximum-depth-of-binary-tree/mandel-17.py
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions merge-two-sorted-lists/mandel-17.py
Original file line number Diff line number Diff line change
@@ -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