Accepted 122ms Javascript solution


  • 0
    P
    var preorderTraversal = function(root) {
        var res = [], stack =[];
        while(root||stack.length){
            while(root){
                if(root.right) stack.push(root.right);
                res.push(root.val)
                root = root.left;
            }
            root = stack.pop();
        }
        return res;
    };
    

Log in to reply
 

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