Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

二叉树的后序遍历 #46

Open
JesseZhao1990 opened this issue Jul 30, 2018 · 0 comments
Open

二叉树的后序遍历 #46

JesseZhao1990 opened this issue Jul 30, 2018 · 0 comments

Comments

@JesseZhao1990
Copy link
Owner

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant