C**5 发帖数: 202 | 1 使用Stack的网上有,要最简单的 Recursive solution | v**m 发帖数: 706 | 2 recursive solution is easier. | b*********s 发帖数: 115 | 3 public class Solution {
public ArrayList postorderTraversal(TreeNode root) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
ArrayList res = new ArrayList();
visit(res, root);
return res;
}
private void visit(ArrayList res, TreeNode root) {
if (root == null) return;
visit(res, root.left);
visit(res, root.right);
res.add(root.val);
}
} | C**5 发帖数: 202 | |
|