Right side view
Mediumtreebfsdfs
Imagine standing on the right of the tree. Return the values you'd see from top to bottom: the last node of every level.
Examples write a tree level by level, with null for a missing child: [3,9,20,null,null,15,7].
Example 1
Input: root = [1,2,3,null,5,null,4] Output: [1,3,4]
Example 2
Input: root = [1,2,3,4] Output: [1,3,4]
The 4 is visible because nothing is to its right on its level.
Constraints
- 0 ≤ number of nodes ≤ 100
- -100 ≤ Node.val ≤ 100
Submit checks your solution against 8 tests, including hidden ones.
// Provided by the judge: keep these definitions
class TreeNode {
constructor(val = 0, left = null, right = null) {
this.val = val
this.left = left
this.right = right
}
}
/**
* @param {TreeNode|null} root
* @return {int[]}
*/
function rightSideView(root) {
}