Binary Tree Level Order Traversal

Trees: DFS & BFS, problem 4 of 8

Binary Tree Level Order Traversal

Medium

LC #102

bfsqueue

Not attempted yet

Given the root of a binary tree, return its values level by level: a list of rows, top to bottom, each row listed left to right.

Example 1

Input: root = [3, 9, 20, None, None, 15, 7]
Output: [[3], [9, 20], [15, 7]]

Example 2

Input: root = [1]
Output: [[1]]

Example 3

Input: root = []
Output: []

Constraints

  • 0 ≤ number of nodes ≤ 2 · 10^4
  • -10^5 ≤ Node.val ≤ 10^5

Python

Loading draft…

Test results

7 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 4 hidden

Run examples, then submit all tests.