leetcode513
/**
* 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的更多相关文章
- [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 ...
- (二叉树 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 ...
- Leetcode513. Find Bottom Left Tree Value找树左下角的值
给定一个二叉树,在树的最后一行找到最左边的值. 示例 1: 输入: 2 / \ 1 3 输出: 1 示例 2: 输入: 1 / \ 2 3 / / \ 4 5 6 / 7 输出: 7 注意: 您可以假 ...
- LeetCode 513. 找树左下角的值(Find Bottom Left Tree Value)
513. 找树左下角的值 513. Find Bottom Left Tree Value 题目描述 给定一个二叉树,在树的最后一行找到最左边的值. LeetCode513. Find Bottom ...
- LeetCode通关:连刷三十九道二叉树,刷疯了!
分门别类刷算法,坚持,进步! 刷题路线参考:https://github.com/youngyangyang04/leetcode-master 大家好,我是拿输出博客来督促自己刷题的老三,这一节我们 ...
随机推荐
- request接收表单提交数据及其中文参数乱码问题
一.request接收表单提交数据: getParameter(String)方法(常用) getParameterValues(String name)方法(常用) getParameterMap( ...
- BZOJ1833 ZJOI2010 count 数字计数 【数位DP】
BZOJ1833 ZJOI2010 count 数字计数 Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包 ...
- mysql update select 用法
之前用SqlServer , update语句对表进行更新:update a set a.xx= (select yy from b) ; 是可以的但是在mysql中,不能直接使用set select ...
- Tornador之初识(一)
一.最简单的web服务器 import socket def handle_request(client): buf = client.recv(1024) client.send("HTT ...
- wpf Tree
code using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...
- Python 运行其他程序
10.4 运行其他程序 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其他脚本,或者程序提供的功能,而不必再次编写实现该功能的代码.为了更好地控制运行的进程, ...
- Python tarfile模块解压报错 invalid mode ('wb') or filename
问题原因 在使用tarfile模块解压一份Linux服务器上的打包文件时, 出现了错误提示: IOError: [Errno 22] invalid mode ('wb') or filename. ...
- lapis 处理接收到的json 数据
备注: 在restful api 开发过程中,大家一般使用的都是json 格式的数据lapis 在处理json 数据上也是比较方便的 1. 使用的api 说明 local ...
- Linux 内核源码目录结构
arch:包含和硬件体系结构相关的代码,每种平台占用一个相应的目录. block:块设备驱动程序 I/O 调度. crypto:常用加密和散列算法(如AES.SHA等),还有一些压缩和CRC校验算法. ...
- PPP PDP 及GPRS
1.相关概念: PDP:Packet Data Protocol 分组数据协议 PLMN:Public Land Mobile Network,公共陆地移动网络 APN:Access Point Na ...