[leetcode-513-Find Bottom Left Tree Value]
Given a binary tree, find the leftmost value in the last row of the tree.
Example 1:
Input:
2
/ \
1 3
Output:
1
Example 2:
Input:
1
/ \
2 3
/ / \
4 5 6
/
7
Output:
7
思路:
层次遍历。每一层保存第一个数即可。
int findBottomLeftValue(TreeNode* root)
{
queue<TreeNode*>que;
if (root!=NULL)que.push(root);
int ret = -;
while (!que.empty())
{
int size = que.size();
for (int i = ; i < size;i++)//一层
{
TreeNode* temp = que.front();
que.pop();
if (i ==)ret = temp->val;
if (temp->left != NULL)que.push(temp->left);
if (temp->right != NULL)que.push(temp->right);
}
}
return ret;
}
[leetcode-513-Find Bottom Left Tree Value]的更多相关文章
- LN : leetcode 513 Find Bottom Left Tree Value
lc 513 Find Bottom Left Tree Value 513 Find Bottom Left Tree Value Given a binary tree, find the lef ...
- [LeetCode] 513. Find Bottom Left Tree Value_ Medium tag: BFS
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...
- 513. Find Bottom Left Tree Value - LeetCode
Question 513. Find Bottom Left Tree Value Solution 题目大意: 给一个二叉树,求最底层,最左侧节点的值 思路: 按层遍历二叉树,每一层第一个被访问的节 ...
- 【LeetCode】513. Find Bottom Left Tree Value 解题报告(Python & C++ & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS DFS Date 题目地址:https:// ...
- 【leetcode】513.Find Bottom Left Tree Value
原题 Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / 1 ...
- 513 Find Bottom Left Tree Value 找树左下角的值
给定一个二叉树,在树的最后一行找到最左边的值. 详见:https://leetcode.com/problems/find-bottom-left-tree-value/description/ C+ ...
- [LC] 513. Find Bottom Left Tree Value
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...
- 513. Find Bottom Left Tree Value
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...
- LeetCode 513. 找树左下角的值(Find Bottom Left Tree Value)
513. 找树左下角的值 513. Find Bottom Left Tree Value 题目描述 给定一个二叉树,在树的最后一行找到最左边的值. LeetCode513. Find Bottom ...
- Leetcode之深度优先搜索(DFS)专题-513. 找树左下角的值(Find Bottom Left Tree Value)
Leetcode之深度优先搜索(DFS)专题-513. 找树左下角的值(Find Bottom Left Tree Value) 深度优先搜索的解题详细介绍,点击 给定一个二叉树,在树的最后一行找到最 ...
随机推荐
- [刷题]算法竞赛入门经典(第2版) 5-12/UVa511 - Do You Know the Way to San Jose?
题意:N张地图,查找某地点在不在某些地图上,若在,使用细节多的地图.使用哪个地图的破要求挺多,细心一点就好. 代码:(Accepted,0.000s) //UVa511 - Do You Know t ...
- (转)static 变量
一. static 变量 static变量大致分为三种用法1. 用于局部变量中,成为静态局部变量. 静态局部变量有两个用法,记忆功能和全局生存期.2. 用于全局变量,主要作用是限制此全局变量被其他的文 ...
- Java 程序员快速上手 Kotlin 11 招
欢迎大家关注腾讯云技术社区-博客园官方主页,我们将持续在博客园为大家推荐技术精品文章哦~ 作者:霍丙乾 近经常会收到一些 "用 Kotlin 怎么写" 的问题,作为有经验的程序员, ...
- MyBatis和Hibernate相比,优势在哪里?
1.开发对比开发速度 hibernate的真正掌握要比Mybatis来得难些.Mybatis框架相对简单很容易上手,但也相对简陋些.个人觉得要用好Mybatis还是首先要先理解好Hibernate. ...
- spring boot --- 初级体验
Spring boot的介绍我就不多说了,网上可以自己看一下. 它的优点就是:快!适合小白,没有复杂的配置文件. 缺点也很明显:坑有些多, 文档略少,报错有时不知道该如何处理. 下面做个最简单的入门: ...
- conda 使用清华大学开源软件镜像
conda 使用清华大学开源软件镜像 Anaconda的安装步骤不在本文的讨论中,我们主要是学习一下如何配置conda的镜像,以及一些问题的解决过程 配置镜像 在conda安装好之后,默认的镜像是官方 ...
- python unittest 测试笔记(一)
测试最基本的原理就是比较预期结果是否与实际执行结果相同,如果相同则测试成功,否则测试失败. python 单元测试官方文档: [Python: 2.7] (https://docs.python.or ...
- css3 linear-gradient渐变效果及兼容性处理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Python os.walk的用法与举例
os.walk(top, topdown=True, onerror=None, followlinks=False) 可以得到一个三元tupple(dirpath, dirnames, filena ...
- Selenium WebDriver + python 自动化测试框架
目标 组内任何人都可以进行自动化测试用例的编写 完全分离测试用例和自动化测试代码,就像写手工测试用例一下,编写excel格式的测试用例,包括步骤.检查点,然后执行自动化工程,即可执行功能自动化测试用例 ...