Description
Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
Examples
Input:
root = [1,2,3,null,5,null,4]Output:
[1,3,4]Explanation:
From right side you see 1, 3, 4.
Input:
root = [5,2,8,1,null,7,9]Output:
[5,8,9]Explanation:
From the right side view: at level 0 observing node 5, at level 1 observing node 8 (rightmost), and at level 2 observing node 9 (rightmost). Node 7 is hidden behind node 9, and nodes 2 and 1 are on the left side.
Input:
root = [10,5,null,3,null,null,null,2]Output:
[10,5,3,2]Explanation:
This tree only has nodes on the left side. From the right side view, it is possible to see all nodes since there are no nodes to the right to block them: 10 at level 0, 5 at level 1, 3 at level 2, and 2 at level 3.
Constraints
- •
Number of nodes is in range [0, 100] - •
-100 ≤ Node.val ≤ 100