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]的更多相关文章

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

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

  3. 【LeetCode】515. Find Largest Value in Each Tree Row 解题报告(Python & C++ & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS DFS 日期 题目地址:https://le ...

  4. 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. 515 Find Largest Value in Each Tree Row 在每个树行中找最大值

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

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

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

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

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

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

随机推荐

  1. 如何在Eclipse下查看JDK源代码

    设置: 1.点 "窗口"-> "首选项" -> "Java" -> "已安装的JRE" 2.此时&qu ...

  2. mongodb新手扫盲

    前言 数据库基本命令 集合(表)命令 增加数据 删除数据 更新数据 查询数据 mongoose的使用 前言 mongodb是什么?, 需fq 如何安装mongodb? 数据库基本命令 显示所有数据库: ...

  3. Hadoop中MapReduce作业流程图

    MapReduce的流程分为11个步骤,4个实体 1.客户端:编写MapReduce的代码,配置作业,提交作业 2.JobTracker:初始化作业,分配作业,与TaskTracker通信,协调整个作 ...

  4. 微信小程序开发之获取openid及用户信息

    1. 获取openid 1.1 获取code 调用接口获取登录凭证(code)进而换取用户登录态信息,包括用户的唯一标识(openid) 及本次登录的会话密钥(session_key).用户数据的加解 ...

  5. JAVA 编程规范

       软件开发技术规范 PTHINK-DEVELOP-JAVA-091010         Java语言编程规范   2009-10-10发布                2009-10-11实施 ...

  6. Linux Set Command

    1. set -e "Exit immediately if a simple command exits with a non-zero status." When this o ...

  7. js 高级算法 - 动态规划

    主要是看了<数据结构与算法>有所感悟,虽然这本书被挺多人诟病的,说这有漏洞那有漏洞,但并不妨碍我们从中学习知识. 其实像在我们前端的开发中,用到的高级算法并不多,大部分情况if语句,for ...

  8. Debian系统简要说明

    Debian这个是我最喜欢也是比较熟悉的一个系统了,BD下做个简要说明 一,APT以及dpkg常见用法如下:功能具体语句 软件源设置     /etc/apt/sources.list 更新软件源数据 ...

  9. Nginx教程(三) Nginx日志管理

    Nginx教程(三) Nginx日志管理 1 日志管理 1.1 Nginx日志描述 通过访问日志,你可以得到用户地域来源.跳转来源.使用终端.某个URL访问量等相关信息:通过错误日志,你可以得到系统某 ...

  10. MySQL数据库使用mysqldump导出数据详解

    mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等.接下来通过本文给大家介绍MySQL数 ...