找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. Vue 环境搭建(win10)

    1.安装node node官网安装地址 推荐安装稳定版本(LTS)以及安装路径为系统盘(C) 查看node安装成功否 注释:以下命令使用 命令提示符(管理员)权限,win10 对user权限的限制了访 ...

  2. Linux下Nginx配置阿里云 SSL证书实现HTTPS访问

    这篇文章主要介绍了nginx配置ssl证书实现https访问的示例 1.服务器系统:Centos 2. 阿里云申请SSL证书 选择“免费版DV SSL”,点击立即购买: 下载证书 列表中找到已签发的证 ...

  3. git 学习(4) ----- git rebase

    使用git rebase 的前提是多人协作下的分支开发,如果是单人开发,那就没有必要使用它了,这是由git rebase 的作用所决定的,git rebase 有两大作用:一个是与主分支保持同步,一个 ...

  4. 清北学堂(2019 4 28 ) part 1

    今天主要用来铺路,打基础 枚举 没什么具体算法讲究,但要考虑更优的暴力枚举方法,例如回文质数,有以下几种思路: 1.挨个枚举自然数,再一起判断是否是回文数和质数,然而一看就不是最优 2.先枚举质数再判 ...

  5. Gradle+IDEA使用说明

    Gradle+IDEA使用说明 导语: IDEA拥有大量的JAVA开发者拥护,相比于开源的eclipse,IDEA拥有更简洁直观的界面,拥有更强大的自动补全功能,号称能“一路敲回车完成编码”.如果把I ...

  6. Quartus16.1布线优化选择,重编译可能会满足时序

    流程 (1)在默认的优化编译下,时序违例. (2)在assignments中选择setting. (3)根据需求,选择不同的优化方式,目前选择性能优先. (4)可以发现时序满足要求. 以上.

  7. Dlib Python 检测人脸特征点 Face Landmark Detection

    首先安装Dlib,Opencv库 Dlib安装链接:http://www.cnblogs.com/as3asddd/p/7237280.html 环境:Mac Sierra 10.12.1 Pytho ...

  8. mybatis 插入 含有美元符号($) 字符串 报 java.lang.IndexOutOfBoundsException: No group 2 的问题

    一:问题描述: 在springboot-security框架生成BCryptPasswordEncoder()方法生成加密后的密码后,带有$符号,导致新增用户的时候插入不了,报(IndexOutOfB ...

  9. 一道简单的CTF登录题题解

    一.解题感受 这道题50分,在实验吧练习场算比较高分,而且通过率只有14%,比较低的水平. 看到这两个数据,一开始就心生惬意,实在不应该呀! 也是因为心态原因,在发现test.php之后,自以为在SQ ...

  10. 快速掌握Nginx(四) —— Nginx日志切片和常用配置总结

    1.Nginx日志管理 1.日志简单介绍 Nginx提供了日志记录的功能,日志文件在对我们管理网站十分有用,通过访问日志(access_log)我们可以获取请求来源.客户端信息.请求的资源等信息:通过 ...