Problem · Tree
Maximum Depth of Binary Tree
Learn this problemProblem statement
Given the root of a finite binary tree, return its maximum depth: the number of nodes on the longest path from the root to a leaf. Return 0 for an empty tree.
Function
maximumDepth(root: TreeNode) → intExamples
Example 1
root = [3,9,20,null,null,15,7]return = 3The longest root-to-leaf path contains three nodes.
Example 2
root = []return = 0An empty tree has depth zero.
Constraints
- The tree contains at most
100000nodes. - Every node value fits in a signed 32-bit integer.
- The input is a finite acyclic binary tree.