/**
* 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的更多相关文章

  1. [Swift]LeetCode530. 二叉搜索树的最小绝对差 | Minimum Absolute Difference in BST

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

  2. LeetCode530. 二叉搜索树的最小绝对差

    题目 又是常见的BST,要利用BST的性质,即中序遍历是有序递增序列. 法一.中序遍历 1 class Solution { 2 public: 3 vector<int>res; 4 v ...

  3. LeetCode783. 二叉搜索树节点最小距离

    题目 和LeetCode530没什么区别 1 class Solution { 2 public: 3 vector<int>ans; 4 int minDiffInBST(TreeNod ...

  4. leetcode_二叉树篇_python

    主要是深度遍历和层序遍历的递归和迭代写法. 另外注意:因为求深度可以从上到下去查 所以需要前序遍历(中左右),而高度只能从下到上去查,所以只能后序遍历(左右中). 所有题目首先考虑root否是空.有的 ...

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

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

随机推荐

  1. 【spring data jpa】好文储备

    [spring data jpa]带有条件的查询后分页和不带条件查询后分页实现  :  https://blog.csdn.net/lihuapiao/article/details/48782843 ...

  2. 安装maven和glassfish及配置环境变

    首先搜索并下载maven3.6.0和glassfish4.1.1(版本看按需要选择). 点击安装包进行安装 安装完成后开始配置环境变量 打开系统环境变量 (1)新建系统变量MAVEN_HOME 变量值 ...

  3. test20180921 手机信号

    题意 分析 我们用形如(l, r, v) 的三元组描述一个区间,这个区间中从l 到r 每隔v 有一个信号站. 考虑一次construct 操作,会添加一个新的区间,并可能将一个已经存在的区间分裂为两个 ...

  4. python 2个dict如何合并

    dictMerged2 = dict( dict1, **dict2 ) 这种效率比较高 refer to: http://www.pythoner.com/13.html

  5. 转-Hive/Phoenix + Druid + JdbcTemplate 在 Spring Boot 下的整合

    Hive/Phoenix + Druid + JdbcTemplate 在 Spring Boot 下的整合 http://blog.csdn.net/balabalayi/article/detai ...

  6. P·C·L 了解

    因为PCL是开源的,所以无论是商用还是研究都是免费的: 赞助商有Open Perception, Willow Garage, NVIDIA, Google, Toyota, Trimble, Urb ...

  7. 【转】每天一个linux命令(7):mv命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/10/27/2743022.html mv命令是move的缩写,可以用来移动文件或者将文件改名(move  ...

  8. 【转】RS232、RS485、TTL电平、CMOS电平

    原文网址:http://blog.sina.com.cn/s/blog_63a0638101018grc.html RS232.RS485.TTL电平.CMOS电平 什么是TTL电平.CMOS电平.R ...

  9. transient解释

    http://www.cnblogs.com/lanxuezaipiao/p/3369962.html

  10. vqmod for opencart插件制作进阶与技巧

    FROM: http://www.sdtclass.com/4799.html 15年的时候,我写过一篇文章<略谈 vqmod for opencart 插件制作过程>,也不知道被哪些人抄 ...