Binary Tree Right Side View
Tree
medium
Score: 40
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 .
Class TreeNode:
val (int)
left (TreeNode)
right (TreeNode)
Input Format
First Parameter - TreeNode root
Output Format
Return the array
Example 1:
Input:
root = [10 12 14 null 7 null 19]
Output:
[10 14 19]
Example 2:
Input:
root = [5 7]
Output:
[5 7]
Constraints:
- The number of nodes in the tree is in the range
[1, 100]
-100 <= Node.val <= 100
- Expected Time Complexity: O(N)
- Expected Space Complexity: O(H), H is the height of the tree