# LeetCode 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,null,null,15,7],

    3
/ \
9  20
/  \
15   7


return its zigzag level order traversal as:

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

class Solution {
public:
/**
* @param root
* @return
*/
vector<vector<int>> zigzagLevelOrder(TreeNode *root) {
vector<vector<int>> ans;
if (root) que.push(root);
int cur = 0;
int flag = 1;
while (cur < que.size()) {
int last = que.size();
vector<int> vec;
flag += 1;
while (cur++ < last) {
TreeNode *tmp = que.front();
vec.push_back(tmp->val);
que.pop();
if (tmp->left)que.push(tmp->left);
if (tmp->right) que.push(tmp->right);
}
cur = 0;
if (flag & 1) reverse(vec.begin(),vec.end());
ans.push_back(vec);
}
return ans;
}

private:
queue<TreeNode *> que;
};


举报原因： 您举报文章：LeetCode 103 Binary Tree Zigzag Level Order Traversal（二叉树层序遍历） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)