master-algorithms-py/trees_and_graphs/find_max_depth_tree.py
2023-07-29 14:28:17 -07:00

7 lines
185 B
Python

def max_depth(root: Optional[TreeNode]) -> int:
if root is None:
return 0
return max(max_depth(root.left) + 1, max_depth(root.right) + 1)