107. Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).

For example:
Given binary tree `[3,9,20,null,null,15,7]`,

```    3
/ \
9  20
/  \
15   7
```

return its bottom-up level order traversal as:

```[
[15,7],
[9,20],
[3]
]```

1.按层访问树，唯一的办法就是使用队列，依次访问每个节点。难点在于怎么确定每层的边界，我使用一个辅助队列，记录每层的元素，当辅助队列空时，代表这一层的所有元素都访问过了。

2.从下到上和从上到下的顺序，可以借助堆栈实现反序。

```public class LevelOrderBottom {
public static List<List<Integer>> levelOrderBottom(TreeNode root) {
if(root == null){
return null;
}
Stack<List<Integer>> stack = new Stack<>();
while(q1.size() > 0){
List<Integer> levelList = new ArrayList<>();
while(q1.size() > 0 && q2.size() > 0){
q2.removeFirst();
if(q1.getFirst().left != null) {
}
if(q1.getFirst().right != null) {
}
}
}
//reverse the stack
List<List<Integer>> list = new ArrayList<>();
while(!stack.isEmpty()) {
}
return list;
}

public static void main(String[] args){
TreeNode root = new TreeNode(3);
TreeNode node1 = new TreeNode(9);
TreeNode node2 = new TreeNode(20);
TreeNode node3 = new TreeNode(15);
TreeNode node4 = new TreeNode(7);
root.left = node1;
root.right = node2;
node2.left = node3;
node2.right = node4;
List<List<Integer>> list = LevelOrderBottom.levelOrderBottom(root);
for(List<Integer> item : list){
for(Integer val : item){
System.out.print(" " + val +" ");
}
System.out.println();
}
}
```