Binary Tree Level Order Traversal
Return binary tree values grouped by depth, from the root down and from left to right within each level.
Example 1
root = [1,2,3,null,4][[1],[2,3],[4]]Explanation
Read root [1], children [2,3], then the only grandchild [4].
Example 2
root = [][]Explanation
An empty tree has no levels.
Example 3
root = [8][[8]]Explanation
A leaf gives one level containing 8.
Constraints
- 0 <= number of nodes <= 2000
- Trees are breadth-first arrays with null holes
Function contract
levelOrderArguments: treeSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[1,2,3,null,4]