# [LeetCode]Binary Tree Postorder Traversal,解题报告

## 题目

Given a binary tree, return the postorder traversal of its nodes' values.

Note: Recursive solution is trivial, could you do it iteratively?

## AC代码

import java.util.ArrayList;

public class BinaryTreePostorderTraversal {
static class TreeNode {
public int val;
public TreeNode left;
public TreeNode right;

public TreeNode(int x) {
this.val = x;
}
}

public static ArrayList<Integer> postorderTraversal(TreeNode root) {
ArrayList<Integer> list = new ArrayList<Integer>();
TreeNode pre = null;

while (!stack.isEmpty() || root != null) {
if (root != null) {
root = root.left;
} else {
root = stack.removeFirst();
if (root.right == null || root.right == pre) {
pre = root;
root = null;
} else {
root = root.right;
}
}
}

return list;
}
}

• 本文已收录于以下专栏：

## Leetcode 103. Binary Tree Zigzag Level Order Traversal 二叉树Zigzag遍历 解题报告

1 解题思想首先这道题和 Leetcode 102. Binary Tree Level Order Traversal 二叉树按层遍历 解题报告 很接近，Zigzag同样是按层遍历，但是区别是对...
• MebiuW
• 2016年09月09日 12:26
• 776

## [leetcode]94. Binary Tree Inorder Traversal@Java解题报告

https://leetcode.com/problems/binary-tree-inorder-traversal/description/ Given a ...

## 【LeetCode】Binary Tree Level Order Traversal II 解题报告

Binary Tree Level Order Traversal II [LeetCode] Given a binary tree, return the bottom-up level orde...

举报原因： 您举报文章：[LeetCode]Binary Tree Postorder Traversal,解题报告 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)