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

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

More Trees problems