Leetcode515. Find Largest Value in Each Tree Row在每个树行中找最大值
您需要在二叉树的每一行中找到最大的值。
示例:
输入: 1 / \ 3 2 / \ \ 5 3 9 输出: [1, 3, 9]
class Solution {
public:
vector<int> largestValues(TreeNode* root)
{
vector<int> res;
if(root == NULL)
return res;
queue<TreeNode *> q;
q.push(root);
while(!q.empty())
{
int len = q.size();
int max = q.front() ->val;
for(int i = 0; i < len; i++)
{
TreeNode* node = q.front();
q.pop();
if(node ->val > max)
{
max = node ->val;
}
if(node ->left)
q.push(node ->left);
if(node ->right)
q.push(node ->right);
}
res.push_back(max);
}
return res;
}
};
Leetcode515. Find Largest Value in Each Tree Row在每个树行中找最大值的更多相关文章
- 515 Find Largest Value in Each Tree Row 在每个树行中找最大值
在二叉树的每一行中找到最大的值.示例:输入: 1 / \ 3 2 / \ \ 5 3 9 输出: [ ...
- 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) 深度优先搜索的解题详细介绍,点击 您需要在二叉树 ...
- [Swift]LeetCode515. 在每个树行中找最大值 | 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 ...
- 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 ...
- [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 ...
- [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 / \ ...
- 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 ...
- (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 ...
随机推荐
- C++相对路径和绝对路径
学习备忘 转自:http://www.cnblogs.com/vranger/p/3820783.html 电脑硬盘E盘下,建文件夹“test”,"test"下建立子文件夹“fil ...
- Redis 常用的数据结构
String 字符串 set get 使用场景: 可以用来作为缓存使用(缓存更新策略和缓存雪崩如何处理) List lpop rpop lpush rpush 使用场景: set 无序集合 使用场景: ...
- Manager 进程间数据共享
#_author:来童星#date:2019/12/11#Managersfrom multiprocessing import Process, Managerdef f(d, l,n): d[n] ...
- 云-腾讯云-云直播:云直播(LVB)
ylbtech-云-腾讯云-云直播:云直播(LVB) 云直播(Live Video Broadcasting,LVB)依托腾讯多年的音视频技术平台,以及全球海量加速节点和领先的音视频 AI 技术,为开 ...
- mac idea解决快捷键的问题
取消mac的快捷键 设置->键盘->快捷键 我这里取消的有:聚焦->显示聚焦搜索 应用快捷键->显示帮助菜单. 类似eclipse的自动提示错误的解决方案(quick fix ...
- PAT甲级——A1129 Recommendation System【25】
Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...
- 18.scrapy_maitian
ershoufang.py # -*- coding: utf-8 -*- import scrapy class ErshoufangSpider(scrapy.Spider): name = 'e ...
- Git初次使用,记录自己看
Git官网下载:https://git-scm.com/downloads 官网如果太慢,可以去这下载:http://www.wmzhe.com/soft-38801.html,注意选择如下图地址下载 ...
- vue项目的实用配置
文件压缩如何去掉console 在使用vue开发项目的过程中,免不了在调试的时候会写许多console,在控制台进行调试:在开发的时候这种输出是必须的,但是build后线上运行时这个东西是不能出现的: ...
- linux系统使用小记
1.解决Ubuntu不能正常使用vi的问题.sudo apt-get remove vim-common sudo apt-get install vim 2.备份linux系统,注意,有的优盘单 ...