Skip to content

Maximum Depth of Binary Tree

01 · Question

Given the root of a binary tree, return its maximum depth.

02 · Solution

Reference solution

1def maxDepth(root: Optional[TreeNode]) -> int:
2 if not root:
3 return 0
4 return 1 + max(maxDepth(root.left), maxDepth(root.right))