https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/
思路:dfs
vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
vector<vector<int>> res;
if (root == NULL) {
return res;
}
queue<TreeNode*> que;
que.push(root);
int i = 0;
while(!que.empty()) {
vector<int> temp;
int len = que.size();
for (int i = 0; i < len; i++) {
TreeNode* node = que.front();
temp.push_back(node->val);
que.pop();
if (node->left) {
que.push(node->left);
}
if (node->right) {
que.push(node->right);
}
}
if (i % 2) {
reverse(temp.begin(), temp.end());
}
i += 1;
res.push_back(temp);
}
return res;
}