import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * } */ public class Solution { /** * * @param root TreeNode类 * @return int整型ArrayList */ public ArrayList<Integer> postorderTraversal (TreeNode root) { // write code here ArrayList<Integer> res = new ArrayList<>(); if(root == null) return res; if(root.left != null){ res.addAll(postorderTraversal(root.left)); }; if(root.right != null){ res.addAll(postorderTraversal(root.right)); }; res.add(root.val); return res; } }