# 107. Binary Tree Level Order Traversal II

[Link](https://leetcode.com/problems/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]
]
```

**Solution**

這題跟之前No. 102 很像，只是順序反過來了。透過linkedList可以把塞在前頭這件事變成O(1)

BFS:

```
class Solution {
    public List<List<Integer>> levelOrderBottom(TreeNode root) {
        List<List<Integer>> ret = new LinkedList<>();
        if(root == null) return ret;
        
        Queue<TreeNode> que = new LinkedList<>();
        que.add(root);
        while(!que.isEmpty()){
            int number = que.size();
            List<Integer> temp = new ArrayList<>();
            for(int i = 0; i < number; i++){
                TreeNode node = que.poll();
                temp.add(node.val);
                if(node.left != null){
                    que.add(node.left);
                }
                if(node.right != null){
                    que.add(node.right);
                }
            }
            ret.add(0, temp);
        }
        return ret;
    }
}
```
