leetcode103
class Solution {
public:
vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
vector<vector<int>> V;
if (root != NULL)
{
int i = ;
queue<TreeNode*> Q;
Q.push(root);
while (!Q.empty())
{
vector<TreeNode*> T;
vector<int> v;
while (!Q.empty())
{
TreeNode* node = Q.front();
Q.pop(); T.push_back(node);
v.push_back(node->val);
}
if (i % == )
{
vector<int> vv;
for (int j = v.size() - ; j >= ; j--)
{
vv.push_back(v[j]);
}
V.push_back(vv);
}
else
{
V.push_back(v);
}
for (auto t : T)
{
if (t->left != NULL)
{
Q.push(t->left);
}
if (t->right != NULL)
{
Q.push(t->right);
}
}
i++;
}
}
return V;
}
};
leetcode103的更多相关文章
- [Swift]LeetCode103. 二叉树的锯齿形层次遍历 | Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- (二叉树 BFS) leetcode103. Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- LeetCode103 BinaryTreeZigzagLevelOrderTraversal(二叉树Z形层次遍历) Java题解
题目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from lef ...
- 32-3题:LeetCode103. Binary Tree Zigzag Level Order Traversal锯齿形层次遍历/之字形打印二叉树
题目 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 ...
- LeetCode103. 二叉树的锯齿形层次遍历
103. 二叉树的锯齿形层次遍历 描述 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 示例 例如,给定二叉树: [3,9,2 ...
- Leetcode103. Binary Tree Zigzag Level Order Traversal二叉树的锯齿形层次遍历
给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 / ...
- LeetCode103 Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- leetcode103:permutations-ii
题目描述 给出一组可能包含重复项的数字,返回该组数字的所有排列 例如: [1,1,2]的排列如下: [1,1,2],[1,2,1], [2,1,1]. Given a collection of nu ...
- LeetCode 103. 二叉树的锯齿形层次遍历(Binary Tree Zigzag Level Order Traversal)
103. 二叉树的锯齿形层次遍历 103. Binary Tree Zigzag Level Order Traversal 题目描述 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再 ...
随机推荐
- UVA-11925 Generating Permutations (逆向思维)
题目大意:给出1~n的某个排列,问由升序变到这个排列最少需要几次操作.操作1:将头两个数交换:操作2:将头一个数移动最后一个位置. 题目分析:反过来考虑,将这个排列变为升序排列,那么这个变化过程实际上 ...
- IOS-网络(小文件下载)
// // ViewController.m // IOS_0131_小文件下载 // // Created by ma c on 16/1/31. // Copyright © 2016年 博文科技 ...
- cx_oracle 安装和配置
前提条件: 已经成功安装python 已经成功安装oracle客户端 1.去官网上下载对应版本的cx_oracle http://cx-oracle.sourceforge.net/ 注意版本必须与p ...
- epoll模型边沿触发
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- 知名第三方编译版tete009 Firefox 24.0
Firefox除了官方版本上还有许多由爱好者自己编译修改的第三方版本. 其中 tete009 是十分流行的一个版本,目前tete009 Firefox 24.0 版本发布. tete009版Firef ...
- Linux运维学习笔记-软硬链接知识总结
文件链接 硬链接,通过索引节点来进行链接 硬链接原理图 硬链接的创建: 直接执行命令“ln 源文件 硬链接文件”,即可完成创建硬链接. 硬链接知识小结: 1.具有相同Inode节点号的多个文件是互 ...
- UVA11732 "strcmp()" Anyone?【左儿子右兄弟Trie】
LINK1 LINK2 题目大意 给你一些字符串,并定义了一个函数(具体见题面) 问你把任意两个字符串放到函数里面得到的值的和是多少 思路 该怎么统计答案呢? 每次考虑当前插入的串和所有已经插入过的串 ...
- [LOJ6198]谢特
loj description 给你一个字符串和一个数组\(w_i\),定义\(\mbox{LCP}(i,j)\)为\(i,j\)两个后缀的最长公共前缀.求\(\max_{i,j}\mbox{LCP} ...
- 关于SSL的error问题
今天模拟网页版微信登录的时候又碰到一个SSLError的问题 requests.exceptions.SSLError: [Errno 1] _ssl.c:503: error:14090086:SS ...
- json-patch 了解
What is JSON Patch? JSON Patch is a format for describing changes to a JSON document. It can be used ...