Javascript solution


  • 2
    R
    var inorderTraversal = function(root) {
        var stack = [],
            res = [];
        
        while(true){
            if(root !== null){
                stack.push(root);
                root = root.left;
            }else{
                if(stack.length === 0) break;
                root = stack.pop();
                res.push(root.val);
                root = root.right;
            }
        }
        
        return res;
    };

Log in to reply
 

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