Description
Given the root of an n-ary tree, return the level order traversal of its nodes values (left to right, level by level).
Examples
Input:
root = [1,null,3,2,4,null,5,6]Output:
[[1],[3,2,4],[5,6]]Explanation:
Level order.
Input:
root = [7,null,9,1,4,2,null,null,6,8,null,null,3,null,5]Output:
[[7],[9,1,4,2],[6,8,3],[5]]Explanation:
The tree has 4 levels. Root node 7 is at level 1. Its children 9,1,4,2 form level 2. The third level contains nodes 6,8,3 (children of nodes 1,4,2 respectively, while node 9 has no children). Finally, node 5 is a child of node 3, forming the fourth level.
Input:
root = []Output:
[]Explanation:
Empty tree case. When the root is null (empty input array), there are no nodes to traverse, so the level order traversal returns an empty array.
Constraints
- •
0 ≤ nodes ≤ 10⁴