Binary Tree Right View
Problem statement
Given the root of a binary tree, imagine viewing the tree from its right side.
Return the value of the visible node at each depth, ordered from the root level downward. For an empty tree, return an empty array.
Function
rightSideView(root: TreeNode) → List<Integer>Examples
Example 1
root = [1,2,3,null,5,null,4]return = [1,3,4]The rightmost visible values at successive levels are 1, 3, and 4.
Example 2
root = [1,null,3]return = [1,3]The right child is visible below the root.
Example 3
root = []return = []An empty tree has no visible levels.
Constraints
- The tree contains between
0and10000nodes. -10^9 <= Node.val <= 10^9.