Skip to content
CodeShare
All problems

Binary Tree Right Side View

List the nodes you'd see looking at a tree from the right.

MediumTreesQueue

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 0 and 100 nodes.
  • -100 <= Node.val <= 100