Simple javascript


  • 0
    S

    RCL traverse and record the stage of current node.

    var rightSideView = function(root) {
        var ret = [];
        helper (root, 0, ret);
        return ret;
    };
    
    function helper (current, stage, ret) {
        if(!current) {
            return;
        }
        
        helper (current.right, stage + 1, ret);
        
        if(!ret[stage]) {
            ret[stage] = current.val;
        }
        
        helper (current.left, stage + 1, ret);
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.