[leetcode-515-Find Largest Value in Each Tree Row]
You need to find the largest value in each row of a binary tree.
Example:
Input:
1
/ \
3 2
/ \ \
5 3 9
Output: [1, 3, 9]
思路:
层次遍历,每一层选出当前层最大值。
vector<int> largestValues(TreeNode* root)
{
vector<int>result;
if (root == NULL)return result;
queue<TreeNode*>que;
que.push(root);
int tempmax = INT_MIN;
while (!que.empty())
{
int levelsize = que.size();
TreeNode* temp;
for (int i = ; i < levelsize;i++)
{
temp = que.front();
que.pop();
if (temp->left != NULL)que.push(temp->left);
if (temp->right != NULL)que.push(temp->right);
tempmax = max(tempmax, temp->val);
}
result.push_back(tempmax);
tempmax = INT_MIN;
}
return result;
}
[leetcode-515-Find Largest Value in Each Tree Row]的更多相关文章
- LN : leetcode 515 Find Largest Value in Each Tree Row
lc 515 Find Largest Value in Each Tree Row 515 Find Largest Value in Each Tree Row You need to find ...
- (BFS 二叉树) leetcode 515. Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 ...
- 【LeetCode】515. Find Largest Value in Each Tree Row 解题报告(Python & C++ & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS DFS 日期 题目地址:https://le ...
- 515. Find Largest Value in Each Tree Row查找一行中的最大值
[抄题]: You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ ...
- 515 Find Largest Value in Each Tree Row 在每个树行中找最大值
在二叉树的每一行中找到最大的值.示例:输入: 1 / \ 3 2 / \ \ 5 3 9 输出: [ ...
- 【leetcode】Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 ...
- 515. Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 ...
- LeetCode 515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)
515. 在每个树行中找最大值 515. Find Largest Value in Each Tree Row 题目描述 You need to find the largest value in ...
- Leetcode之深度优先搜索(DFS)专题-515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)
Leetcode之深度优先搜索(DFS)专题-515. 在每个树行中找最大值(Find Largest Value in Each Tree Row) 深度优先搜索的解题详细介绍,点击 您需要在二叉树 ...
- [LeetCode] Find Largest Value in Each Tree Row 找树每行最大的结点值
You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 ...
随机推荐
- 2017最新修复福运来完整运营中时时彩源码PC+手机版本功能齐全
QQ:1395239152 2017-3.14最新修复福运来完整运营版时时彩源码PC+手机版本功能齐全 使用php+mysql开发,并带有完整数据库.截图!!! 注意哈 带手机版 以下截图均为测 ...
- Guvav:Options使用和避免NULL
JAVA中的null null是Java中一个很重要的概念.null设计初衷是为了表示一些不确定的东西.null是Java中的关键字,它是大小写敏感的,你不能将null写成Null或NULL,编译器将 ...
- Oracle数据库悲观锁与乐观锁详解
数据的锁定分为两种方法,第一种叫做悲观锁,第二种叫做乐观锁.什么叫悲观锁呢,悲观锁顾名思义,就是对数据的冲突采取一种悲观的态度,也就是说假设数据肯定会冲突,所以在数据开始读取的时候就把数据锁定住.而乐 ...
- Collection学习目录
1.Collection<E>.Iterable<T>和Iterator<E>接口 2.ArrayList源码分析 3.LinkedList源码解析 4.Vecto ...
- 通过ssh远程ipython notebook登录使用服务器
远程服务器有时候我们这里通过虚拟机登录服务器的winclient会发生冲突,怎么办呢?曲线救国,使用SSH登录. 首先在远程机器上,启动IPython notebooks服务: remote_user ...
- MyBatis之TypeHandler
在大学写web应用的时候经常会遇到这么个问题,当我要插入一条数据,某个数据是Date类型,数据库中却是VARCHAR类型,这个时候可能会傻乎乎的先把这个数据自己手动转换成String类型再插入到数据库 ...
- su 切换用户的提示"This account is currently not available"
su 切换ivalue用户时,提示"This account is currently not available"; 首先进入/etc/passwd文件中是否添加ivalue用户 ...
- DB太大?一键帮你收缩所有DB文件大小(Shrink Files for All Databases in SQL Server)
本文介绍一个简单的SQL脚本,实现收缩整个Microsoft SQL Server实例所有非系统DB文件大小的功能. 作为一个与SQL天天打交道的程序猿,经常会遇到DB文件太大,把空间占满的情况: 而 ...
- 3.Java 加解密技术系列之 SHA
Java 加解密技术系列之 SHA 序 背景 正文 SHA-1 与 MD5 的比较 代码实现 结束语 序 上一篇文章中介绍了基本的单向加密算法 — — MD5,也大致的说了说它实现的原理.这篇文章继续 ...
- HTML中部分标签的嵌套问题
书写HTML结构的时候,对于标签的嵌套问题,在我发现这个问题之前,都不在自己的考虑之中,还傻傻的以为标签之间是可以进行百搭的! 其实,有些标签是不能进行随意嵌套,如果你没有深受其害,你是不会发现它的存 ...