# 103. Binary Tree Zigzag Level Order Traversal

[Link](https://drive.google.com/drive/u/0/folders/1OOgTaRfaPOnDKu95CA7I1FfUcb8X8j2U)

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).

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

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

return its zigzag level order traversal as:\\

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

**Solution**

跟102, 107根本一家人

T: O(N)

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