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 ...
随机推荐
- C++中出现的计算机术语1
access labels(訪问标号) 类的成员能够定义为 private,这能够防止使用该类型的代码訪问该成员. 成员还能够定义为 public,这将使该整个程序中都可訪问成员. address( ...
- HDU1849 Rabbit and Grass()
用异或看取得的值是否为0推断 思想换没搞懂 #include<stdio.h> int main() { int ans,n,a; while(scanf("%d",& ...
- HttpWeb服务器之--用OO方式写
虽然写的不是很好,但 最终解释权以及版权归13东倍所有! package com.web; import java.io.IOException; public class Test { public ...
- mooon编译系统介绍(可复用Makefile)
mooon编译系统介绍(可复用Makefile).pdf(ChinaUnix下载) CSDN下载:http://download.csdn.net/detail/aquester/5626929 mo ...
- C++历史
C++历史 早期C++ •1979: 首次实现引入类的C(C with Classes first implemented) 1.新特性:类.成员函数.继承类.独立编译.公共和私有访问控制.友元.函数 ...
- socket网络编程的一些基础知识
源地址:http://blog.csdn.net/roger_77/article/details/1453049 目录: 1) 什么是套接字? 2) Internet 套接字的两种类型 3) 网络理 ...
- WOJ 1055
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char s[6]={0} ...
- Object.Instantiate 实例
static function Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object ...
- HTML5系列之——applicationCache对象
ApplicationCache主要简单介绍: applicationCache对象实现HTML5相应WEB离线功能.以下我们来主要解说applicationCache对象的一些主要功能和方法 app ...
- POJ--3268--Silver Cow Party【SPFA+邻接表】
题意:一些牛要去某一点參加聚会,然后再回到自己家,路是单向的,问花费时间最多的那头牛最少须要花费多长时间. 思路:从聚会地点返回,相当于是从某一点到其它各个点的最短路径.从牛的家中走到聚会地点,能够把 ...