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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Trees problems