Practice/Meta/Leetcode 199. Binary Tree Right Side View
CodingMust
Imagine standing to the right of a binary tree and looking at it from that perspective. You can only see certain nodes — specifically, the rightmost node at each level of the tree.
Given the root of a binary tree, return a list of the values of the nodes you can see when viewing the tree from its right side. The values should be ordered from top to bottom, corresponding to each level of the tree.
Example 1:
`
Input: root = [1, 2, 3, null, 5, null, 4]
Tree structure:
1
/
2 3
\
5 4
Output: [1, 3, 4] Explanation: Looking from the right side:
Example 2:
` Input: root = [1, 2, null, 3] Tree structure: 1 / 2 / 3
Output: [1, 2, 3] Explanation: Even though all nodes are on the left branch, each is the rightmost (and only) node at its level `
Example 3:
Input: root = [] Output: [] Explanation: An empty tree has no visible nodes