JavaScript solution with iteration


  • 3
    L
    function inorderTraversal(node) {
    	var stack = [];
    	var res = [];
    	while (node || stack.length) {
    		// drill left
    		while (node) {
    			stack.push(node);
    			node = node.left;
    		}
    		// print & go to right child
    		node = stack.pop();
    		res.push(node.val);
    		node = node.right;
    	}
    	return res;
    }

Log in to reply
 

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