找BST树中节点之间的最小差值。

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
//BST树中序遍历就是递增的序列,相邻两个数的差值,找最小
class Solution {
public:
int min_res = INT_MAX;
TreeNode* pre; int getMinimumDifference(TreeNode* root) {
helper(root);
return min_res;
} void helper(TreeNode*root){
if (!root)
return;
helper(root->left); //1 if (pre)
min_res = min(min_res, abs(root->val - pre->val));
pre = root; helper(root->right); //2
}
};

【easy】530. Minimum Absolute Difference in BST的更多相关文章

  1. 【leetcode_easy】530. Minimum Absolute Difference in BST

    problem 530. Minimum Absolute Difference in BST 参考 1. Leetcode_easy_530. Minimum Absolute Difference ...

  2. 【LeetCode】530. Minimum Absolute Difference in BST 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

  3. 51. leetcode 530. Minimum Absolute Difference in BST

    530. Minimum Absolute Difference in BST Given a binary search tree with non-negative values, find th ...

  4. 【leetcode】1200. Minimum Absolute Difference

    题目如下: Given an array of distinct integers arr, find all pairs of elements with the minimum absolute ...

  5. 【LeetCode】1200. Minimum Absolute Difference 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode ...

  6. LeetCode 530. Minimum Absolute Difference in BST (二叉搜索树中最小绝对差)

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

  7. 530. Minimum Absolute Difference in BST

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

  8. [LeetCode&Python] Problem 530. Minimum Absolute Difference in BST

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

  9. 530.Minimum Absolute Difference in BST 二叉搜索树中的最小差的绝对值

    [抄题]: Given a binary search tree with non-negative values, find the minimum absolute difference betw ...

随机推荐

  1. Linux系统编程之事件驱动

    通常,我们写服务器处理模型的程序时,有以下几种模型:(1)每收到一个请求,创建一个新的进程,来处理该请求:(2)每收到一个请求,创建一个新的线程,来处理该请求:(3)每收到一个请求,放入一个事件列表, ...

  2. 详解volatile 关键字与内存可见性

    先来看一个例子: public class VolatileTest {            public static void main(String[] args) {           T ...

  3. Linux(Ubuntu)使用日记------markdown文档转化为word文档

    Linux(Ubuntu)使用日记------markdown文档转化为word文档

  4. ERP常见问题总结处理

    1. ERP系统的重量录入组件设计不合理易导致录入错误 如下图所示: 修正方法: 1. 更正数据 使用SQL语句更正数据,已经生产完成,作为单据重新录入比较麻烦 UPDATE e_wms_materi ...

  5. win10双系统安装卸载ubuntu

    安装 1. 官网下载需要安装的Ubuntu版本 2. 格式化U盘,用UltraISO软件将Ubuntu写入U盘 3. 设置电脑U盘启动,重启电脑安装,注意安装时关闭在线下载,否则会安装很久 4. 安装 ...

  6. [题解]小X的液体混合

    版权说明:来自 石门ss学校 Guohao OJ ,禁止转载 题目描述 虽然小X不喜欢化学原理,但他特别喜欢把一大堆液体倒在一起. 现在小X有n种液体,其中m对会发生反应.现在他想把这n种液体按某种顺 ...

  7. 关于vue移动端的适配

    http://blog.csdn.net/z1712636234/article/details/77881685

  8. elastic的gc相关

    https://www.jianshu.com/p/1f450826f62e   gc原理介绍 相关优化 https://zhaoyanblog.com/archives/319.html 问题 ht ...

  9. Web开发基础-Node.js-01

    01-浏览器工作原理 1)人机交互部分(ui) 2)网络请求部分(socket) 3)javascript引擎 4)渲染引擎(解析html,css) 5)数据存储部分(cookie,本地存储等) -- ...

  10. HTML&CSS_基础02

    一.实体 # 1. 一些符号如 “<”. “>”. “ ”. ”©“等,不能使用其本身,需要借助实体(即转义字符),格式通常为:& (字符对应实体); 如 &lt . &a ...