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. 层序遍历 ...
随机推荐
- SQL Server JDBC驱动中sqljdbc和sqljdbc4区别
为了支持向后兼容以及可能的升级方案,JDBC Driver 2.0 在每个安装包中都包括 2 个 JAR 类库:sqljdbc.jar 和 sqljdbc4.jar. qljdbc.jar 类库提供对 ...
- 解决.Net MVC EntityFramework Json 序列化循环引用问题.
以前都是到处看博客,今天小菜也做点贡献,希望能帮到大家. 废话不多说,直接进入正题. 用过.net MVC的同学应该都被json序列化报循环引用错误这个问题骚扰过.网上有一些解决办法,但是都治标不治本 ...
- Android 利用摄像头指尖测试心率
过摄像头来获得心率,搜了一下这个技术真不是噱头,据说在iPhone早有实现,主要原理是:当打开软件时,手机的闪光灯也会被自动打开,用户将手指放在摄像头上时,指尖皮下血管由于有血液被压入,被光源照射的手 ...
- 静态资源库CDN服务
使用静态资源库可以访问线上资源文件,比如jquery库.bootstrap库.使用百度静态资源库的居多,但是发现百度暂时不支持https协议,bootcdn是一个不错的选择. 百度静态资源公共库 优点 ...
- 【原创】Libjpeg 库使用心得(一) JPEG图像DCT系数的获取和访问
[原创]继续我的项目研究,现在采用Libjpeg库函数来进行处理,看了库函数之后发现C语言被这些人用的太牛了,五体投地啊...废话不多说,下面就进入正题. Libjpeg库在网上下载还是挺方便的,这里 ...
- MYSQL this function has none of deterministic no sql ......错误
This function has none of DETERMINISTIC, NO SQL解决办法 创建存储过程时 出错信息: ERROR 1418 (HY000): This function ...
- QML开源游戏
http://google.github.io/VoltAir/doc/main/html/index.htmlhttp://blog.qt.io/blog/2010/02/26/qt-box2d-i ...
- QT实现appendSheet(QAxObject的一种Add + Move的方法)
一般地,熟悉VB.VC的同学都知道,要将新增的excel表单添加到表单的末尾,是很简单的事情,直接调用Add函数,传入对应的函数形参,就能实现将新增表单插入到末尾,但是通过QT的QAxObject实现 ...
- 通过jstack定位在线执行java系统故障_案例1
问题描写叙述: 在一个在线执行的java web系统中,会定时执行一个FTP上传的任务,结果有一天发现,文件正常生成后却没有上传. 问题初步分析: 1.查看日志文件 发现这个任务仅仅打印了開始进入FT ...
- c++类的实例化,有没有new的区别
A a; A * a = new a(); 以上两种方式皆可实现类的实例化,有new的区别在于: 1.前者在堆栈中分配内存,后者为动态内存分配,在一般应用中是没有什么区别的,但动态内存分配会使对象的可 ...