### 题目

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]
]


### 还是用List缓冲元素

#### 代码（迭代版）

/**
* Definition for a binary tree node.
* public class TreeNode {
*     int val;
*     TreeNode left;
*     TreeNode right;
*     TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
if (root == null) { return res; }
List<TreeNode> buffer = new ArrayList<>();
boolean leftToRight = true;
while (!buffer.isEmpty()) {
List<Integer> nums = new ArrayList<>();
int size = buffer.size();
for (int i = 0; i < size; i++) {
TreeNode node = buffer.remove(0);
if (node != null) {
if (leftToRight) { // 根据方向开关插入结果
} else {
}
}
}
leftToRight = !leftToRight;
}
return res;
}
}


#### 递归版

/**
* Definition for a binary tree node.
* public class TreeNode {
*     int val;
*     TreeNode left;
*     TreeNode right;
*     TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
if (root == null) { return res; }
List<TreeNode> buffer = new ArrayList<>();
zigzagLevelOrderRecur(res,buffer,new Boolean(true));
return res;
}
public void zigzagLevelOrderRecur(List<List<Integer>> res, List<TreeNode> buffer, boolean fromLeftToRight) {
if (buffer.isEmpty()) { return; }
List<Integer> nums = new ArrayList<>();
int size = buffer.size();
for (int i = 0; i < size; i++) {
TreeNode node = buffer.remove(0);
if (node != null) {
if (fromLeftToRight) {
} else {