Maximum Depth of Binary Tree
Return the maximum number of nodes on a root-to-leaf path. An empty binary tree has depth zero.
Example 1
root = [1,null,2,null,3]3Explanation
The right-only chain 1->2->3 contains three nodes on its deepest path.
Example 2
root = []0Explanation
An empty tree has depth zero.
Example 3
root = [7,8,9]2Explanation
The root and either child give depth two.
Constraints
- 0 <= number of nodes <= 10000
- Trees are breadth-first arrays with null holes
Function contract
maxDepthArguments: treeSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[1,null,2,null,3]