Leetcode145. 二叉树的后序遍历

题目描述

题目链接:https://leetcode.cn/problems/binary-tree-postorder-traversal/description/
Leetcode145. 二叉树的后序遍历_第1张图片

代码实现

class Solution {
    List<Integer> tree = new ArrayList<>();
    public List<Integer> postorderTraversal(TreeNode root) {
        postorder(root);
        return tree;
    }
    public void postorder(TreeNode root){
        if(root==null){
            return;
        }
        postorder(root.left);
        postorder(root.right);
        tree.add(root.val);
    }
}

你可能感兴趣的:(Java,leetcode,算法,链表)