JesseZhao1990/algorithm

二叉树的后序遍历

JesseZhao1990 opened this issue · 0 comments

image

/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var postorderTraversal = function(root) {
    var res = []
    function traversal(node,res){
        if(!node) return;
        traversal(node.left,res);
        traversal(node.right,res);
        res.push(node.val);
    }
    traversal(root,res);
    return res;
};

leetcode原题地址:https://leetcode-cn.com/problems/binary-tree-postorder-traversal/description/