Skip to content

Level Order Traversal

MediumTrees
Decode it first. Clues, constraints, pattern and plan before any code.

Given the root of a binary tree, return its values level by level: a list of lists, where each inner list holds one level's values from left to right.

Trees in the examples are written in level order (top to bottom, left to right), with null for a missing child, the same way the tests build them.

[3, 9, 20, null, null, 15, 7]  →  [[3], [9, 20], [15, 7]]
[1]                            →  [[1]]
[]                             →  []

Constraints

  • 0 <= number of nodes <= 2000
  • -1000 <= Node.val <= 1000