Given the root of a binary tree, imagine standing on its right side. Return the values of the nodes you can see, from top to bottom: the last node on each level.
Trees are written level by level, with null for a missing child.
Examples
Example 1
- Input
- root = [1, 2, 3, null, 5, null, 4]
- Output
- [1, 3, 4]
Example 2
- Input
- root = [1, null, 3]
- Output
- [1, 3]
Example 3
- Input
- root = []
- Output
- []
Constraints
- The tree has between
0and100nodes. -100 <= Node.val <= 100