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 大家好,我是拿输出博客来督促自己刷题的老三,这一节我们 ...
随机推荐
- [转载][QT][SQL]sql学习记录5_sqlite视图(View)
转载自:http://www.runoob.com/sqlite/sqlite-view.html SQLite 视图(View) 视图(View)只不过是通过相关的名称存储在数据库中的一个 SQLi ...
- OC中使用单例模式
static Config * instance = nil; +(Config *) Instance { @synchronized(self) { if(nil == instance) { [ ...
- SGU495Kids and Prizes(数学期望||概率DP||公式)
495. Kids and Prizes Time limit per test: 0.25 second(s) Memory limit: 262144 kilobytes input: stand ...
- hadoop常见错误总结三
问题导读:1.... could only be replicated to 0 nodes, instead of 1 ...可能的原因是什么?2.Error: java.lang.NullPoin ...
- CentOS 6.6下安装OpenOffice4.0
最近由于项目需要,要在公司服务器上安装Openoffice,网上搜了一些资料后成功安装,现分享给大家. 1.首先先下载好需要的rpm包:Apache_OpenOffice_4.0.0_Linux_x8 ...
- 《DSP using MATLAB》示例Example7.10
代码: ws1 = 0.2*pi; wp1 = 0.35*pi; wp2 = 0.65*pi; ws2 = 0.8*pi; As = 60; tr_width = min((wp1-ws1), (ws ...
- 关于simulink hdlcoder的优化问题
HDL Block Properties中包含有多个优化选项. 1,delay balance 当其他分支优化过后,可能会引入一个或几个周期的delay,这时候需要在与其并行的几条信号路径上也加上de ...
- linux命令ls -l的默认排序方式
差不多快实现完了ls -l,但是在测试阶段发现一个问题,对于包含[a-ZA-Z]之外的字符,系统的排序方式并不一样. 很想了会儿,总算发现原来它的排序方式是无视[a-ZA-Z]之外的字符的 至于怎么发 ...
- [转载]树莓派新版系统上使用mjpg-streamer获取USB摄像头和树莓派专用摄像头RaspiCamera图像
树莓派新版系统上使用mjpg-streamer获取USB摄像头和树莓派专用摄像头RaspiCamera图像 网上有很多关于mjpg-stream移植到树莓派的文章,大部分还是使用的sourceforg ...
- 汇编_指令_DS*10H的含义
在8086存储器系统中,20位地址总线的地址是物理地址.但是由于8086内部寄存器都是16位的, 用16位寄存器直接访问20位存储器空间显然不可能,所以8086CPU使用了存储器分段的办法.这 样内存 ...