6
0
:0
0
Route Tree Breadth Read
Route Tree Breadth Read
Easy
Trees
In "Route Tree Breadth Read", the binary tree is provided in array form (level-order with null gaps).
Return node values grouped by depth from top to bottom and left to right.
Example 1
Input:
root = [5,6,7,null,8,9,null]Output:
[[5],[6,7],[8,9]]For input root = [5,6,7,null,8,9,null], nodes are grouped by depth from top to bottom, yielding [[5],[6,7],[8,9]]. Therefore, return [[5],[6,7],[8,9]].
Example 2
Input:
root = [15,16,17,18,null,null,19]Output:
[[15],[16,17],[18,19]]For input root = [15,16,17,18,null,null,19], nodes are grouped by depth from top to bottom, yielding [[15],[16,17],[18,19]]. Therefore, return [[15],[16,17],[18,19]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[5,6,7,null,8,9,null]Expected Output:
[[5],[6,7],[8,9]]Test Case 2
Input:
[15,16,17,18,null,null,19]Expected Output:
[[15],[16,17],[18,19]]