Level Order Traversal of a Binary Tree
BINARY TREE
BREADTH-FIRST SEARCH
Problem
Given the root node of a binary tree, return an array of array, where each subarray contains the values of the tree's nodes at each level from top to bottom and left to right.
Example 1
treeByLevels([1,2,3,null,4,5]) // return [[1], [2,3], [4,5]]
Example 2
treeByLevels([1,2,3,null,null,null,4,5]) // return [[1], [2,3], [4], [5]]
Loading...
Loading...Loading...