Binary tree level-order traversal

Problem Given the root of a binary tree, return its level-order traversal — the node values grouped level by level, from left to right.

Input / Output

  • Input: the root of a binary tree.
  • Output: a list of lists, one inner list of values per level (top to bottom).

Constraints

  • 0 <= number of nodes <= 2000; the tree may be empty (return []).

Example

  • Tree [3, 9, 20, null, null, 15, 7] -> [[3], [9, 20], [15, 7]]
asked …
LeaderboardSalaryAccount