###### Middle-题目70：103. Binary Tree Zigzag Level Order Traversal

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,#,#,15,7},

    3
/ \
9  20
/  \
15   7

return its zigzag level order traversal as:
[
[3],
[20,9],
[15,7]
]

/**
* 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) {

boolean isReverse = true;
List<List<Integer>> result=new ArrayList();
List<Integer> temp=new ArrayList<Integer>();
if(root==null)
return result;
while(!queue.isEmpty())
{
TreeNode current=queue.remove();
int curLevel=levelqueue.remove();
//System.out.println(current.val+" level="+curLevel);

if(curLevel==result.size())
{
}
else
{
if(isReverse)
Collections.reverse(temp);
isReverse = !isReverse;
temp=new ArrayList<Integer>();
}
if(current.left!=null)
{
}
if(current.right!=null)
{
}
}
if(isReverse)
Collections.reverse(temp);
result.remove(0);
//  Collections.reverse(result);
return result;
}
}

4ms,beats 4.14%,众数3ms,45.49%

#### 【LeetCode】103. Binary Tree Zigzag Level Order Traversal 解题报告

2016-05-28 12:04:05

#### LeetCode 103:Binary Tree Zigzag Level Order Traversal

2015-05-31 00:34:47

#### Binary Tree Zigzag Level Order Traversal -- LeetCode

2014-04-26 04:31:29

#### Leetcode 103. Binary Tree Zigzag Level Order Traversal 二叉树Zigzag遍历 解题报告

2016-09-09 12:26:27

#### LeetCode 103 Binary Tree Zigzag Level Order Traversal

2014-03-28 15:18:46

#### 【LeetCode-面试算法经典-Java实现】【103-Binary Tree Zigzag Level Order Traversal（二叉树分层Z字形遍历）】

2015-08-08 06:35:14

#### Leetcode 树 Binary Tree Zigzag Level Order Traversal

2014-05-13 20:54:47

#### LeetCode102 Binary Tree Level Order Traversal Java

2016-04-23 14:20:55

#### 102. Binary Tree Level Order Traversal [easy] (Python)

2016-05-10 14:40:58

#### LeetCode --- 107. Binary Tree Level Order Traversal II

2015-04-17 16:46:33

## 不良信息举报

Middle-题目70：103. Binary Tree Zigzag Level Order Traversal