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. linux下MongoDB客户端shell基本操作

    MongoDB 是一款NoSql数据库,没有固定的模式,即同一个集合中的不同文档结构可以不同,如:第一条记录{name:”xiaoming”},第二条记录:{name:”xiaoli”,age:15} ...

  2. Java IO和NIO文章目录

    1.java IO详尽解析 2.深入分析 Java I/O 的工作机制 3.InputStream类详解 4.OutputStream类详解 5.JAVA的节点流和处理流 6.FileInputStr ...

  3. 关于Dubbo一个接口多个实现的解决方案

    如题,其实这个问题在官方文档中已经说明了.我直接贴图就好了 更多学习请参考:minglisoft.cn/technology

  4. Appium 1.6.4 环境搭建流程(Java, Android+IOS, Windows+Mac)

    Appium1.6.4已经出来一段时间了,快速给大家串一下怎么搭建,贴了下载链接 1 基础环境: Windows + Mac: Java JDK 1.8+ (需配置环境变量),Appium1.6.4的 ...

  5. B507实验室打印机连接方法

    一.准备工具 实验室打印机内网IP地址:172.16.135.41 ,这个地址要看具体的打印机地址(可能会更换). 从实验室QQ群(土匪窝)上下载打印机驱动,如下图所示. 3. 非常重要的事情:请链接 ...

  6. 007---Hibernate基本映射标签和属性介绍

    一.映射文件的基本结构举例: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-// ...

  7. 开涛spring3(6.6) - AOP 之 6.6 通知参数

    前边章节已经介绍了声明通知,但如果想获取被被通知方法参数并传递给通知方法,该如何实现呢?接下来我们将介绍两种获取通知参数的方式. 使用JoinPoint获取:Spring AOP提供使用org.asp ...

  8. JavaScript基础(.....持续待更)

    javascript热身 一.你知道,为什么JavaScript非常值得我们学习吗? 1. 所有主流浏览器都支持JavaScript. 2. 目前,全世界大部分网页都使用JavaScript. 3. ...

  9. R语言-Kindle特价书爬榜示例 & 输出HTML小技巧(转)

    自从买了kindle以后,总是想要定期刷有没有便宜的书,amazon经常有些1元/2元的书打特价,但是每次都去刷那些榜单太麻烦了,而且榜单又不能按照价格排名,捞书有点累 所以自己用R语言的rvest包 ...

  10. Java IO流之缓冲流

    一.缓冲流简介 二.BufferedInputStream 三.其他三种缓冲流