反转前序遍历
public class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
List<Integer> result = new ArrayList<Integer>();
Deque<TreeNode> stack = new ArrayDeque<TreeNode>();
if (root != null) stack.push(root);
while (!stack.isEmpty()) {
TreeNode curr = stack.pop();
result.add(curr.val);
if (curr.left != null) stack.push(curr.left);
if (curr.right != null) stack.push(curr.right);
}
Collections.reverse(result);
return result;
}
}