Medium · Trees

Find Leaves of Binary Tree

Given the root of a binary tree, repeatedly remove all of its current leaves until the tree is empty, and return the values removed in each round as a list of lists, first round first; values within a round may be in any order, and an empty tree returns [].

Examples

Example 1

[1,2,3,4,5]

Output: [4,5,3][2][1]

Example 2

[1,2,3,null,4]

Output: [4,3][2][1]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Trees problems