6
0
:0
0
Menu Tree Level Listing: Family Registry Edition
Menu Tree Level Listing: Family Registry Edition
Hard
Trees
In "Menu Tree Level Listing: Family Registry Edition", 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 = [26,27,28,null,29,30,null]Output:
[[26],[27,28],[29,30]]For input root = [26,27,28,null,29,30,null], nodes are grouped by depth from top to bottom, yielding [[26],[27,28],[29,30]]. Therefore, return [[26],[27,28],[29,30]].
Example 2
Input:
root = [36,37,38,39,null,null,40]Output:
[[36],[37,38],[39,40]]For input root = [36,37,38,39,null,null,40], nodes are grouped by depth from top to bottom, yielding [[36],[37,38],[39,40]]. Therefore, return [[36],[37,38],[39,40]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[26,27,28,null,29,30,null]Expected Output:
[[26],[27,28],[29,30]]Test Case 2
Input:
[36,37,38,39,null,null,40]Expected Output:
[[36],[37,38],[39,40]]