Description
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Examples
Input:
root = [1,null,3,2,4,null,5,6]Output:
3Explanation:
Three levels deep.
Input:
root = []Output:
0Explanation:
Empty tree has no nodes, so the maximum depth is 0.
Input:
root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10]Output:
4Explanation:
The tree has 4 levels: root node 1 at level 1, nodes 2,3,4,5 at level 2, nodes 6,7,8 at level 3, and nodes 9,10 at level 4.
Constraints
- •
0 ≤ nodes ≤ 10⁴