您需要在二叉树的每一行中找到最大的值。

示例:

输入: 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在每个树行中找最大值的更多相关文章

  1. 515 Find Largest Value in Each Tree Row 在每个树行中找最大值

    在二叉树的每一行中找到最大的值.示例:输入:           1         /  \        3   2       /  \    \        5   3    9 输出: [ ...

  2. 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 ...

  3. Leetcode之深度优先搜索(DFS)专题-515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)

    Leetcode之深度优先搜索(DFS)专题-515. 在每个树行中找最大值(Find Largest Value in Each Tree Row) 深度优先搜索的解题详细介绍,点击 您需要在二叉树 ...

  4. [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 ...

  5. 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 ...

  6. [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 ...

  7. [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 / \ ...

  8. 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 ...

  9. (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 ...

随机推荐

  1. Idea中创建maven骨架的命令

    如下:通过命令化在Idea中创建骨架成功后,以后项目直接引用导入骨架直接在依赖框架上面进行相关模块开发: 1.mvn archetype:create-from-project 2.mvn clean ...

  2. thinkphp扩展配置

    扩展配置可以支持自动加载额外的自定义配置文件,并且配置格式和项目配置一样. 设置扩展配置的方式如下(多个文件用逗号分隔): // 加载扩展配置文件 'LOAD_EXT_CONFIG' => 'u ...

  3. 数论剩余系——cf1089F

    关于模和互质,很好的题目 /* n两个质因子 x,y有 ax+by=n-1 ax+by=n-1 ax+1+by=n y|ax+1 gcd(x,y)=1 ax%y,a取[1,y-1],就会有[1,y-1 ...

  4. x-杂项-maven-repository-lombok-intro:使用PROJECT LOMBOK减少BOILERPLATE代码

    ylbtech-杂项-maven-repository-lombok-intro:使用PROJECT LOMBOK减少BOILERPLATE代码 1.返回顶部 1. REDUCING BOILERPL ...

  5. JAVA 文件的上传下载

    一.上传文件 1.使用 transferTo 上传 @ResponseBody @RequestMapping(value = "/file/upload") public Res ...

  6. day19_生成器

    20180730 初次上传 20180731 更新,4.列表生成式,以及部分注释 #!/usr/bin/env python # -*- coding:utf-8 -*- # ************ ...

  7. 求N!中素数的个数

    int degree_in_fact(int n, int x)//求n!中素数x的次数 { if(m) return degree_in_fact(n/x,x)+n/x; ; }

  8. let能否完全替代IIFE

    let是什么 http://es6.ruanyifeng.com/#docs/let 最近,我写了一篇关于syntax of Java’s IIFE pattern的文章,来解释为什么我们用现在的方式 ...

  9. Office2016只安装三件套方法

    转载 Office2016只安装三件套方法(word,ppt,excel) 2019-03-01 23:30:03 Kellen5l 阅读数 11618更多 分类专栏: Office   版权声明:本 ...

  10. Python全栈开发:css引入方式

    css的四种引入方式: 1.行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐使用. <p style="color: red;backgr ...