145.94 二叉树的中序&后序遍历【简单题】

145

function action(curNode, curRes) {
    if (!curNode) {
        return curRes;
    }
    curRes = action(curNode.left, curRes);
    curRes = action(curNode.right, curRes);
    curRes.push(curNode.val);

    return curRes;
}

/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var postorderTraversal = function(root) {
    return action(root, []);
}

94

function action(curNode, curRes) {
    if (!curNode) {
        return curRes;
    }
    curRes = action(curNode.left, curRes);
    curRes.push(curNode.val);
    curRes = action(curNode.right, curRes);

    return curRes;
}

/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var inorderTraversal = function(root) {
    return action(root, []);
};

results matching ""

    No results matching ""