6
0
:0
0
Level Grouping of Nodes
Level Grouping of Nodes
Medium
Trees
In "Level Grouping of Nodes", 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 = [14,15,16,null,17,18,null]Output:
[[14],[15,16],[17,18]]For input root = [14,15,16,null,17,18,null], nodes are grouped by depth from top to bottom, yielding [[14],[15,16],[17,18]]. Therefore, return [[14],[15,16],[17,18]].
Example 2
Input:
root = [24,25,26,27,null,null,28]Output:
[[24],[25,26],[27,28]]For input root = [24,25,26,27,null,null,28], nodes are grouped by depth from top to bottom, yielding [[24],[25,26],[27,28]]. Therefore, return [[24],[25,26],[27,28]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[14,15,16,null,17,18,null]Expected Output:
[[14],[15,16],[17,18]]Test Case 2
Input:
[24,25,26,27,null,null,28]Expected Output:
[[24],[25,26],[27,28]]