Back to course home
0% completed
Vote For New Content
Solution: Maximum Depth of N-ary Tree
Problem Statement
Given a root of the n-ary tree, return the maximum depth of the tree.
The maximum depth refers to the longest path from the root node to any leaf node.
Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value.
Examples
Example 1:
- Input: root =
[1,null,2,3,4,null,5]
- Expected Output:
3 - Justification: The path from the root node
1to the farthest leaf node5goes through nodes1 -> 2 -> 5, making the depth3.
Example 2:
- Input: root =
.....
.....
.....
Like the course? Get enrolled and start learning!