1. var rightSideView = function (root) {
    2. const list = []
    3. // dfs的顺序为 根节点 -> 右子节点 -> 左子节点
    4. const dfs = (node, count) => {
    5. if (!node) return
    6. // 如果是当前层的第一个访问的说明是该层的最右节点
    7. if(count === list.length) {
    8. list.push(node.val)
    9. }
    10. count++
    11. dfs(node.right, count)
    12. dfs(node.left, count)
    13. }
    14. dfs(root, 0)
    15. return list
    16. };