<문제>
<답안>
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/
var rightSideView = function(root) {
if (!root) return [];
let array = [];
let rightArray = [];
search(root, 1);
function search(root, level) {
if (root) {
if (array.length < level) {
array.push(root.val);
}
search(root.right, level+1);
search(root.left, level+1);
} else {
return ;
}
}
return array;
};