leetcode先刷_Binary Tree Level Order Traversal II
非常easy标题,在后面,我不认为它不是那么简单的回答更多的。我们将编写,没有人啊。
预购在基层上,加上节省每一层,加上从下往上的输出,是一家vector而一个stack那么问题,没有他,但另一方面-cooked首尔。
class Solution {
public:
vector<vector<int> > levelOrderBottom(TreeNode *root) {
vector<vector<int> > res;
if(root == NULL) return res;
queue<TreeNode*> que;
stack<vector<int> > s;
vector<int> tpres;
TreeNode *pNode;
que.push(root);
que.push(NULL);
while(!que.empty()){
pNode = que.front();
que.pop();
if(pNode == NULL){
s.push(tpres);
tpres.clear();
if(que.empty())
break;
else{
que.push(NULL);
continue;
}
}
tpres.push_back(pNode->val);
if(pNode->left)
que.push(pNode->left);
if(pNode->right)
que.push(pNode->right);
}
while(!s.empty()){
res.push_back(s.top());
s.pop();
}
return res;
}
};
leetcode先刷_Binary Tree Level Order Traversal II的更多相关文章
- Java for LeetCode 107 Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- LeetCode 107 Binary Tree Level Order Traversal II(二叉树的层级顺序遍历2)(*)
翻译 给定一个二叉树,返回从下往上遍历经过的每一个节点的值. 从左往右,从叶子到节点. 比如: 给定的二叉树是 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回它从下 ...
- [LeetCode] 107. Binary Tree Level Order Traversal II 二叉树层序遍历 II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- (二叉树 BFS) leetcode 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- LeetCode 107. Binary Tree Level Order Traversal II (二叉树阶层顺序遍历之二)
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- leetcode 107 Binary Tree Level Order Traversal II ----- java
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- LeetCode 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- leetcode题解:Tree Level Order Traversal II (二叉树的层序遍历 2)
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
- Java [Leetcode 107]Binary Tree Level Order Traversal II
题目描述: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, fro ...
随机推荐
- Find the minimum线段树成段更新
问题 G: Find the minimum 时间限制: 2 Sec 内存限制: 128 MB 提交: 83 解决: 20 [ 提交][ 状态][ 讨论版] 题目描述 Given an int ...
- Delphi中使用GDI+进行绘图(2)
2)使用IGDIPlus接口 (1)下载安装所需软件 可以在以下地址下载IGDI+最新的安装程序. http://www.mitov.com/products/igdi+ www.igdiplus.o ...
- 14.2.4 InnoDB Undo Logs
14.2.4 InnoDB Undo Logs : 一个Undo log (或者成为回滚段) 是一个存储区域 持有被活动事务修改的数据的copy. 如果另外的事务需要看原始的数据(作为一致性读操作的一 ...
- python random模块 - 小驹的专栏 - 博客频道 - CSDN.NET
python random模块 - 小驹的专栏 - 博客频道 - CSDN.NET python random模块 分类: python 2011-11-15 15:31 6037人阅读 评论(2) ...
- Disable root 账号登陆
1. 改动文件: /etc/ssh/sshd_config #PermitRootLogin yes 改动为: PermitRootLogin no 2. 重新启动ssh进程 /etc/init.d/ ...
- TCP、UDP数据包大小的限制(UDP数据包一次发送多大为好)——数据帧的物理特性决定的,每层都有一个自己的数据头,层层递减
1.概述 首先要看TCP/IP协议,涉及到四层:链路层,网络层,传输层,应用层. 其中以太网(Ethernet)的数据帧在链路层 IP包在网络层 TCP或UDP包在传输层 TCP或UDP中的数据(Da ...
- delphi cmd(4个例子都是通过管道取得)
//K8执行DOS并返回结果 function RunDosCommand(Command: string): string; var hReadPipe: THandle; hWritePipe: ...
- 对于stackoverflow的中文翻译的相关问题
我们非常多朋友都给我留言说.希望我翻译一下stackoverflow的问题以及答案,首先我也非常愿意为大家翻译,在能够帮助大家的同一时候,对我本人的技能的提升有优点:可是工作量实在太大,所以我不可能翻 ...
- Office 2016九大新功能
Office 2016将于2015年秋季正式公布,下面是九大新功能. 预測 基于数据透视表的时间分组建模 联机分析(OLAP)下的PowerView 数据透视表(PivotTable)建模的自己主动关 ...
- 胡na娜、少年和恩师-写在甲午冬的仅仅言片语及感想
[写在全新为移动互联网而生的Zoomla!逐浪CMS2 x2.1公布前] 恩师, 他来到这个乡村中学,带着自己的书.吉它和理想, 用自己最好的三年青春浇灌了这一代人, 在我辍学时,给我鼓舞,帮助我继续 ...