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 ...
随机推荐
- vim编码方式设置
建议vim的_vimrc文件里设置如下的编码方式: set encoding=utf-8 set fileencodings=ucs-bom,utf-8,cp936 set fileencoding= ...
- 关于SecureCRT不能显示输入、换行不正常
网上绿色破解版的SecureCRT会碰到这种问题,即输入字符不显示在终端.换行后下一行的行首有很大一段退格: 如上,输入的指令不显示:回车后下一行的起始位置不对. 碰到这种问题,在波特率.奇偶校验.停 ...
- C/C++ 字符、字符串转十六进制(支持中文字符串转换)
#include <string> // std::string #include <sstream> // std::stringstream /** * #purpose ...
- Python 学习杂项
#print("Hello World!") #name = "nihfjkds" age = 454 num1 = 1 num2 = 2 #print(nam ...
- 「题解」:$Game$
问题 B: $Game$ 时间限制: 1 Sec 内存限制: 256 MB 题面 题面谢绝公开. 题解 对于最初加入的每一个元素开桶记录出现次数. 然后记录一个前p个元素最大值. 先由先手玩家取走一 ...
- Vue+Iview+Node 项目结构和配置
1.项目调整后的目录 api:数据接口定义 assets:静态文件 components:组件 config:项目相关配置 driective:指令 router:路由 store:状态管 ...
- SP1296 SUMFOUR - 4 values whose sum is 0
传送门 解题思路 四个数组一起做有点炸.先把他们合并成两个数组,然后让一个数组有序,枚举另一个数组的元素,二分即可.时间复杂度\(O(n^2logn^2)\) 代码 #include<iostr ...
- 牛客多校第四场 A meeting 树的半径
题意: 有一棵树,树上有许多人,他们要聚会,找一个点使得所有人到这个点的距离的最大值最小. 题解: 首先,以一个有人的点为根,求一个生成树,删掉所有没有人的子树,保证所有的悬挂点(只连接一条边的点)都 ...
- Windows下 vundle的安装和使用
准备工作 1. 安装git 去官网下载,安装即可. 2. 添加git的环境变量 并将Git 的安装路径加入环境变量Path,如 D:\Program Files\Git\cmd 然后运行cmd,输入 ...
- 夏令营501-511NOIP训练16——数字转换
传送门:QAQQAQ 题意:如果一个数x的约数和(不包括它本身,下同)比它本身小,那么x可以变成它的约数和:如果对于某个y>x且y的约数和为x,那么x也可以变成y.例如,4可以变为3,1可以变为 ...