Binary Tree Level Order Traversal II --leetcode C++
考察点
- 广度优先遍历--层次遍历
- STL内容器的用法
广度优先遍历的时候,首先应该想到的就是借助于队列。还需要在遍历下一层之前保存当前层节点的数量
代码很简单:
class Solution {
public:
vector<vector<int> > levelOrderBottom(TreeNode* root) {
vector<vector<int> >vec;
if(root==NULL){
return vec;
}
queue <TreeNode *>qu;
qu.push(root);
int count=;//保存每一层的节点数量 while(!qu.empty()){
vector <int> v;
while(count>=){
TreeNode *node; node=qu.front();
qu.pop();
v.push_back(node->val);
count--;
if(node->left!=NULL){
qu.push(node->left);
}
if(node->right!=NULL){
qu.push(node->right);
}
}
vec.insert(vec.begin(),v);
count=qu.size();
} }
};
Binary Tree Level Order Traversal II --leetcode C++的更多相关文章
- Binary Tree Level Order Traversal II——LeetCode
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- Binary Tree Level Order Traversal II [LeetCode]
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- Binary Tree Level Order Traversal II leetcode java
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
- LeetCode之“树”:Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal 题目链接 题目要求: Given a binary tree, return the level order traversal o ...
- 【LeetCode】107. Binary Tree Level Order Traversal II (2 solutions)
Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal ...
- 35. Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal OJ: https://oj.leetcode.com/problems/binary-tree-level-order-trave ...
- LeetCode_107. Binary Tree Level Order Traversal II
107. Binary Tree Level Order Traversal II Easy Given a binary tree, return the bottom-up level order ...
- Binary Tree Level Order Traversal,Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal Total Accepted: 79463 Total Submissions: 259292 Difficulty: Easy G ...
- 102/107. Binary Tree Level Order Traversal/II
原文题目: 102. Binary Tree Level Order Traversal 107. Binary Tree Level Order Traversal II 读题: 102. 层序遍历 ...
随机推荐
- Java的跨平台原理
JAVA的跨平台原理 JAVA的跨平台原理 Java是一种简单易用.完全面向对象.有平台无关性.安全可靠的.主要面向Internet的开发工具.Java自从1995年正式面世以来,它的快速发展已经使整 ...
- Android 实现GIF播放(解码)
实现原理很简单,先把GIF动画解码成多张Bitmap图片,然后放到AnimationDrawable里面去逐一播放即可. GifHelper代码: package com.android.view; ...
- cloneNode小结
js原生API中有个cloneNode,还有一个可选的参数, true代表复制子节点,包括任何包裹在标签之间的东西,当然包括文本节点,也就是标签之间有什么,它就会不假思索的全部都克隆一份. false ...
- perl 爬取上市公司业绩预告
<pre name="code" class="python">use LWP::UserAgent; use utf8; use DBI; use ...
- 怎样从一个DLL中导出一个C++类
原文作者:Alex Blekhman 翻译:朱金灿 原文来源: http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx 译 ...
- gcc 的include path和lib path调整
`gcc -print-prog-name=cc1plus` -v `g++ -print-prog-name=cc1plus` -v ------------------------------ ...
- SBT模版
/*Author:WNJXYK*/ #include<cstdio> using namespace std; ; struct SBT{ int left; int right; int ...
- 多名Uber司机被指刷单遭封号 一周薪水为0
昨天,一司机在Uber“司机之家”办公地墙上写了泄愤的话 摄/法制晚报记者 苏妮 司机展示的账单显示,上周的薪水几乎为零,上面用英文标注了“欺诈行为”的字样 摄/法制晚报记者 苏妮 法制晚报讯(记者 ...
- The Highest Mark(01背包)
The Highest Mark Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- CF# 260 A. Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the m ...