Accepted JavaScript Solution, Short Clean


  • 0
    Z
    var postorderTraversal = function(root) {
        let rst = [], stack = [];
        if(root === null) return rst;
        
        stack.push(root);
        while(stack.length !== 0){
            let cur = stack.pop();
            rst.unshift(cur.val);
            if(cur.left !== null) stack.push(cur.left);
            if(cur.right !== null) stack.push(cur.right);
        }
        return rst;
    };
    

Log in to reply
 

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