leetcode530
/**
* 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 {
List<int> list = new List<int>();
void postOrder(TreeNode Node)
{
if (Node != null)
{
list.Add(Node.val);
}
if (Node != null && Node.left != null)
{
postOrder(Node.left);
}
if (Node != null && Node.right != null)
{
postOrder(Node.right);
}
} public int GetMinimumDifference(TreeNode root)
{
postOrder(root); list = list.OrderBy(x => x).ToList();
var min = Int32.MaxValue;
for (int i = ; i < list.Count - ; i++)
{
min = Math.Min(min, Math.Abs(list[i] - list[i + ]));
}
Console.WriteLine(min);
return min;
}
}
https://leetcode.com/problems/minimum-absolute-difference-in-bst/#/description
leetcode530的更多相关文章
- [Swift]LeetCode530. 二叉搜索树的最小绝对差 | Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- LeetCode530. 二叉搜索树的最小绝对差
题目 又是常见的BST,要利用BST的性质,即中序遍历是有序递增序列. 法一.中序遍历 1 class Solution { 2 public: 3 vector<int>res; 4 v ...
- LeetCode783. 二叉搜索树节点最小距离
题目 和LeetCode530没什么区别 1 class Solution { 2 public: 3 vector<int>ans; 4 int minDiffInBST(TreeNod ...
- leetcode_二叉树篇_python
主要是深度遍历和层序遍历的递归和迭代写法. 另外注意:因为求深度可以从上到下去查 所以需要前序遍历(中左右),而高度只能从下到上去查,所以只能后序遍历(左右中). 所有题目首先考虑root否是空.有的 ...
- LeetCode通关:连刷三十九道二叉树,刷疯了!
分门别类刷算法,坚持,进步! 刷题路线参考:https://github.com/youngyangyang04/leetcode-master 大家好,我是拿输出博客来督促自己刷题的老三,这一节我们 ...
随机推荐
- C# NPOI导出Excel和EPPlus导出Excel
转自:http://www.cnblogs.com/tanpeng/p/6155749.html 系统中经常会使用导出Excel的功能.之前使用的是NPOI,但是导出数据行数多就报内存溢出. 最近看到 ...
- java环境变量 Path 与CLASSPATH
1.Windows操作系统根据Path环境变量来查找命令,Linux操作系统则根据PATH环境变量来查找命令 因为Windows操作系统不区分大小写,设置Path和PATH并没有区别,而Linux系统 ...
- 重磅来袭,开源Asp.Net MVC网上商城BrnShop正式发布,提供源码下载(转)
BrnShop网上商城是以Asp.Net mvc3为基础开发的网上商城,源代码完全开源(企业版的源代码目前还没有完全整理完成,一旦整理完成也全部开源). 啥话也不说了,直接上源码:下载源码(由于公司服 ...
- Start Developing iOS Apps (Swift) 开始开发iOS应用(Swift)
http://www.cnblogs.com/tianjian/category/704953.html 构建基础的用户界面 Build a Basic UI http://www.cnblogs.c ...
- C# 线程会合实例
有这样一个题目:四个线程t1,t2,t3,t4,向4个文件中写入数据,要求:t1只能写入“1”,t2只能写入“2”,t3只能写入“3”,t4只能写入“4”,对4个文件A,B,C,D写入如下内容: A: ...
- C语言发送邮件
c语言发送邮件Linux下使用c语言发送邮件 领导交代一个任务,需要将服务器上的df -hl的执行结果定时发给他. 尝试使用sendmail来发邮件,但是后来放弃了,并不是所有的服务器上都安装了sen ...
- asm数据文件迁移(asm–>asm)
rman迁移操作 [oracle@localhost oradata]$ rman target / Recovery Manager: Release 10.2.0.3.0 - Producti ...
- package.json 文件中的版本号
版本号,格式:"主要版本,次要版本,补丁版本" 指定版本:比如1.2.2,遵循"主版本,次要版本,补丁版本"的格式规定,安装时只安装指定版本. 波浪号(tild ...
- Angular 4 路由时传递数据
路由时传递数据的方式有 1. 在查询参数中传递数据 2. 在路由路径中传递参数 3. 在路由配置中传递参数 一.在查询参数中传递数据 在前一节的基础上,我们增加路由数据传递 2. 接收参数的地方 3. ...
- MySQL集群Percona XtraDB Cluster安装搭建步骤详解
http://www.linuxidc.com/Linux/2017-05/143501.htm http://blog.csdn.net/thundermeng/article/details/52 ...