* Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ publicclass{ public List<Integer> ans = new ArrayList<Integer>(); public List<Integer> postorderTraversal(TreeNode root){ if (root == null) return ans; if (root.left != null) postorderTraversal(root.left); if (root.right != null) postorderTraversal(root.right); ans.add(root.val); return ans; } }
近期评论