给定一个二叉树,在树的最后一行找到最左边的值。

示例 1:

输入: 2 / \ 1 3 输出: 1

示例 2:

输入: 1 / \ 2 3 / / \ 4 5 6 / 7 输出: 7

注意: 您可以假设树(即给定的根节点)不为 NULL。

class Solution {
public:
int maxDepth;
int res;
int findBottomLeftValue(TreeNode* root)
{
maxDepth = 0;
GetAns(1, root);
return res;
} void GetAns(int depth, TreeNode* root)
{
if(root == NULL)
return;
if(depth > maxDepth)
{
maxDepth = depth;
res = root ->val;
}
if(root ->left)
GetAns(depth + 1, root ->left);
if(root ->right)
GetAns(depth + 1, root ->right);
}
};

Leetcode513. Find Bottom Left Tree Value找树左下角的值的更多相关文章

  1. 513 Find Bottom Left Tree Value 找树左下角的值

    给定一个二叉树,在树的最后一行找到最左边的值. 详见:https://leetcode.com/problems/find-bottom-left-tree-value/description/ C+ ...

  2. LeetCode 513. 找树左下角的值(Find Bottom Left Tree Value)

    513. 找树左下角的值 513. Find Bottom Left Tree Value 题目描述 给定一个二叉树,在树的最后一行找到最左边的值. LeetCode513. Find Bottom ...

  3. Leetcode之深度优先搜索(DFS)专题-513. 找树左下角的值(Find Bottom Left Tree Value)

    Leetcode之深度优先搜索(DFS)专题-513. 找树左下角的值(Find Bottom Left Tree Value) 深度优先搜索的解题详细介绍,点击 给定一个二叉树,在树的最后一行找到最 ...

  4. Java实现 LeetCode 513 找树左下角的值

    513. 找树左下角的值 给定一个二叉树,在树的最后一行找到最左边的值. 示例 1: 输入: 2 / \ 1 3 输出: 1 示例 2: 输入: 1 / \ 2 3 / / \ 4 5 6 / 7 输 ...

  5. [Swift]LeetCode513. 找树左下角的值 | 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 ...

  6. 领扣(LeetCode)找树左下角的值 个人题解

    给定一个二叉树,在树的最后一行找到最左边的值. 示例 1: 输入: 2 / \ 1 3 输出: 1 示例 2: 输入: 1 / \ 2 3 / / \ 4 5 6 / 7 输出: 7 注意: 您可以假 ...

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

  8. (二叉树 BFS) leetcode513. 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 ...

  9. 【题解】#6622. 「THUPC 2019」找树 / findtree(Matrix Tree+FWT)

    [题解]#6622. 「THUPC 2019」找树 / findtree(Matrix Tree+FWT) 之前做这道题不理解,有一点走火入魔了,甚至想要一本近世代数来看,然后通过人类智慧思考后发现, ...

随机推荐

  1. 【JZOJ6368】质树(tree)

    description 大神 wyp 手里有棵二叉树,每个点有一个点权.大神 wyp 的这棵树是质树,因为 随便找两个不同的点 u, v,只要 u 是 v 的祖先,都满足 u 和 v 的点权互质. 现 ...

  2. day23 内置函数,匿名函数,递归

    Python之路,Day11 = Python基础11 内置函数divmod(x, y)   # (商, 模)enumerate(可迭代对象)     # (序号,值)eval(字符串) # 把字符串 ...

  3. csp-s模拟100,101T1,T2题解

    题面:https://www.cnblogs.com/Juve/articles/11799325.html 我太蒻了只会T1T2 组合: 欧拉路板子?不会呀... 然后打了个优化,防止暴栈 #inc ...

  4. 计算几何——圆卡精度cf1059D

    double 在1e17以后就不能顾及小数,所以用一下加精度的技巧 sqrt(r*r-d*d)=sqrt(r+d)*sqrt(r-d) 遇到误差在几位以内的注意要修改二分的精度,用最大的数据去乘以精度 ...

  5. 线段树区间合并+k维空间的曼哈顿距离——cf1093G好题

    和去年多校的CSGO一样,用状态压缩来求Manhattan距离的最大值 然后要用线段树维护一下区间最大值 /* k维空间给定n个点,两个操作 1 i b1 b2 .. bk : 修改第i个点的坐标 2 ...

  6. 常用css初始化样式(淘宝)

    最简单粗暴的css初始化样式就是:*{padding:0:margin:0}(不推荐) 淘宝的样式初始化: body, h1, h2, h3, h4, h5, h6, hr, p, blockquot ...

  7. Web开发-Servlet&HTTP&Request

    <!doctype html>02 - JavaEE - Servlet&HTTP&Request figure:first-child { margin-top: -20 ...

  8. js 获取自定义属性值

    html: <p tid="1" onClick="change()">111</p> <p tid="2" ...

  9. oracle 如何在一个数据库创建多个实例

    实例:是一个非固定的.基于内存的基本进程与内存结构.当服务器关闭后,实例也就不存在了. 数据库(Database)指的是固定的.基于磁盘的数据文件.控制文件.日志文件.参数文件和归档日志文件等. 一般 ...

  10. 建立 CRAMFS 包

    下载 cramfs 工具 从 http://prdownloads.sourceforge.net/cramfs/cramfs­1.1.tar.gz下载源代码包. 把下载包拷贝到 dev_home/t ...