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 ...
随机推荐
- -force_load
Crash Log: Last Exception Backtrace: 0 CoreFoundation 0x2f087f06 __exceptionPrepro ...
- VirtualBox集群建立和网络配置
安装 1. 安装 安装Oracle VM VirtualBox之后,新建一个虚拟机,制定好内存等信息,开始安装操作系统,这里安装ubuntu-12.04.2-desktop-i386版本. 2. 拷贝 ...
- c# in depth 之泛型实参的类型推断
调用泛型方法时,指定类型实参常常会显得很多余.为简化工作,c#2编译器被赋予了一定的“智能”,让你在调用方法时,不需要显式声明类型实参. 在深入讨论这个主题之前,必须强调一下:类型推断只适用于泛型方法 ...
- 通过加载Kernel32来动态判断 当前操作系统32bit还是64bit
工作原理:通过加载Kernel32来获取IsWow64Process 函数然后通过函数的地址操作,执行函数的操作. 在程序中只要我们获取了一个函数的地址,就可以找到正确的方法执行这个函数. 但是这种方 ...
- 通过Type.InvokeMethod实现方法的重载
版本:.NET Framework 3.5 先来一个反射调用方法的例子: using System; using System.Reflection; class Example { static v ...
- Codechef Not a Triangle题解
找出一个数组中的三个数,三个数不能组成三角形. 三个数不能组成三角形的条件是:a + b < c 两边和小于第三边. 这个问题属于三个数的组合问题了.暴力法可解,可是时间效率就是O(n*n*n) ...
- table显示边框问题,隐藏行线,列线
只显示上边框 <table frame=above> 只显示下边框 <table frame=below> 只显示左.右边框 <table frame=vsides> ...
- frontend http 前端名字定义问题
https://www.winfae.com/admin/api/menu haproxy 日志: Jun 24 13:04:49 localhost haproxy[14817]: 115.236. ...
- 解决CentOS无法显示中文字体 | 系统运维 | Web2.0
解决CentOS无法显示中文字体 | 系统运维 | Web2.0 About Me 博客园 devops 前端 张家港水蜜桃 傍晚好! 2013年09月12日 17:56:08 ...
- queue C++
#include <iostream> using namespace std; class DequeEmptyException { public: DequeEmptyExcepti ...