# 二叉树的后序遍历

<p>给定一个二叉树，返回它的 <em>后序&nbsp;</em>遍历。</p>

<p><strong>示例:</strong></p>

<pre><strong>输入:</strong> [1,null,2,3]  
   1
    \
     2
    /
   3 

<strong>输出:</strong> [3,2,1]</pre>

<p><strong>进阶:</strong>&nbsp;递归算法很简单，你可以通过迭代算法完成吗？</p>


## template

```java

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

	TreeNode(int x) {
		val = x;
	}
}

class Solution {
	public List<Integer> postorderTraversal(TreeNode root) {
		List<Integer> list = new ArrayList<>();
		Stack<TreeNode> nodeStack = new Stack<>();
		TreeNode nodeTemp = root;
		TreeNode preNode = null;
		while (nodeTemp != null || !nodeStack.isEmpty()) {
			while (nodeTemp != null) {
				nodeStack.push(nodeTemp);
				nodeTemp = nodeTemp.left;
			}
			nodeTemp = nodeStack.peek();
			if (nodeTemp.right == null || nodeTemp.right == preNode) {
				nodeTemp = nodeStack.pop();
				list.add(nodeTemp.val);
				preNode = nodeTemp;
				nodeTemp = null;
			} else {
				nodeTemp = nodeTemp.right;
			}
		}
		return list;
	}
}

```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```