/**
* Definition for a binary tree node.
* public class TreeNode {
* public int val;
* public TreeNode left;
* public TreeNode right;
* public TreeNode(int x) { val = x; }
* }
*/
public class Solution {
Stack<TreeNode> S = new Stack<TreeNode>(); List<List<TreeNode>> list = new List<List<TreeNode>>(); List<TreeNode> left = new List<TreeNode>(); private void postNode(TreeNode node)
{
if (node != null)
{
S.Push(node);
if (node.left != null)
{
if (node.left.left == null && node.left.right == null)
{
left.Add(node.left);
}
postNode(node.left);
}
if (node.right != null)
{
postNode(node.right);
}
if (node.left == null && node.right == null)
{
list.Add(S.ToList());
} S.Pop();
}
} public int FindBottomLeftValue(TreeNode root)
{
postNode(root); list = list.OrderByDescending(x => x.Count).ToList(); var result = root.val;
foreach (var l in list)
{
result = l[].val;
break;
}
return result;
}
}

https://leetcode.com/problems/find-bottom-left-tree-value/#/description

leetcode513的更多相关文章

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

  2. (二叉树 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 ...

  3. Leetcode513. Find Bottom Left Tree Value找树左下角的值

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

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

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

  5. LeetCode通关:连刷三十九道二叉树,刷疯了!

    分门别类刷算法,坚持,进步! 刷题路线参考:https://github.com/youngyangyang04/leetcode-master 大家好,我是拿输出博客来督促自己刷题的老三,这一节我们 ...

随机推荐

  1. 每天一个linux命令(文件操作):【转载】find 命令的参数详解

    find一些常用参数的一些常用实例和一些具体用法及注意事项. 1.使用name选项: 文件名选项是find命令最常用的选项,要么单独使用该选项,要么和其他选项一起使用.可以使用某种文件名模式来匹配文件 ...

  2. ASP.NET Core 中的SEO优化(3):自定义路由匹配和生成

    前言 前两篇文章主要总结了CMS系统两个技术点在ASP.NET Core中的应用: <ASP.NET Core 中的SEO优化(1):中间件实现服务端静态化缓存> <ASP.NET ...

  3. eclipse显示/隐藏代码行号

    Window→Preferences→General→Editors→TextEditors→勾选Show line numbers

  4. 【requirejs】JS模块化工具requirejs教程

    初识requirejs 随着网站功能逐渐丰富,网页中的js也变得越来越复杂和臃肿,原有通过script标签来导入一个个的js文件这种方式已经不能满足现在互联网开发模式,我们需要团队协作.模块复用.单元 ...

  5. np.random 的使用

    random 有很多地方会用到. 参考这篇: http://www.cnblogs.com/CheeseZH/p/4593349.html

  6. lapis 处理接收到的json 数据

     备注:      在restful api 开发过程中,大家一般使用的都是json 格式的数据lapis       在处理json 数据上也是比较方便的   1. 使用的api 说明 local ...

  7. TCP和UDP通信(C#网络编程) ---- 系列文章

    文章系列目录 C#网络编程系列文章(一)之Socket实现异步TCP服务器 C#网络编程系列文章(二)之Socket实现同步TCP服务器 C#网络编程系列文章(三)之TcpListener实现异步TC ...

  8. 理解AI的角度

    <经济学人>去年出了一期很经典的封面,封面里将全球各大高科技平台企业如谷歌.亚马逊之许描绘成正在采油的钻井,寓意很明显,在数字经济时代,大平台正在开采数字化的石油——大数据,而开采出来的大 ...

  9. Linux 之 hugepage 大页内存理论

    HugePages是通过使用大页内存来取代传统的4kb内存页面,使得管理虚拟地址数变少,加快了从虚拟地址到物理地址的映射以及通过摒弃内存页面的换入换出以提高内存的整体性能.尤其是对于8GB以上的内存以 ...

  10. http请求发生了两次(options请求)

    前言 自后台restful接口流行开来,请求了两次的情况(options请求)越来越普遍.笔者也在实际的项目中遇到过这种情况,做一下整理总结. 文章书写思路: 为什么发生两次请求 http的请求方式, ...