Easy · Trees

Print leaves

Given the root of a binary tree, return the values of its leaves (nodes with no children) in left-to-right order; an empty tree has no leaves.

Examples

Example 1

[1,2,3,4,5,·,6]

Output: [4, 5, 6]

Example 2

[5,3,8,1,·,·,9]

Output: [1, 9]

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