53. Binary Tree Right Side View

Imagine standing to the right of the tree. Return the values of the nodes you can see, from top to bottom (the last node of each level).

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]
Hint 1

BFS: take the last node of every level.

Hint 2

DFS visiting right before left: the first node you meet at each depth is visible.

TreeBFSDFS