【easy】530. Minimum Absolute Difference in BST
找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的更多相关文章
- 【leetcode_easy】530. Minimum Absolute Difference in BST
problem 530. Minimum Absolute Difference in BST 参考 1. Leetcode_easy_530. Minimum Absolute Difference ...
- 【LeetCode】530. Minimum Absolute Difference in BST 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...
- 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 ...
- 【leetcode】1200. Minimum Absolute Difference
题目如下: Given an array of distinct integers arr, find all pairs of elements with the minimum absolute ...
- 【LeetCode】1200. Minimum Absolute Difference 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode ...
- LeetCode 530. Minimum Absolute Difference in BST (二叉搜索树中最小绝对差)
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- 530. Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- [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 ...
- 530.Minimum Absolute Difference in BST 二叉搜索树中的最小差的绝对值
[抄题]: Given a binary search tree with non-negative values, find the minimum absolute difference betw ...
随机推荐
- Jeecg-Boot前后端分离版
Jeecg-Boot前后端分离版http://www.jeecg.org/forum.php?gid=229 Jeecg-Boot 快速开发平台http://boot.jeecg.org/user/l ...
- 为App添加Log日志文件
using System; using System.Globalization; using System.IO; using System.Text; using System.Windows.F ...
- MyBatis 3源码解析(三)
三.getMapper获取接口的代理对象 1.先调用DefaultSqlSession的getMapper方法.代码如下: @Override public <T> T getMapper ...
- 京东商品及评论爬虫(selenium)
代码查看https://gitee.com/MarkPolaris/reptile/tree/master/jd 中的gly和demo03
- MSSQL-最佳实践-Always Encrypted
摘要 在SQL Server安全系列专题月报分享中,往期我们已经陆续分享了:如何使用对称密钥实现SQL Server列加密技术.使用非对称密钥实现SQL Server列加密.使用混合密钥实现SQL S ...
- vmware创建虚拟机不识别网卡
今天在给虚拟机添加网卡的时候,出现了虚拟机不识别新加的网卡,很纳闷,连的一样的端口组,为什么新加的网卡识别不了呢 然后查看pci设备,发现网卡的驱动为 AMD 79C970 PCnet32- LANC ...
- Sql知识点总结
一.数据库对象:表(table) 视图(view) 序列(sequence) 索引(index) 同义词(synonym) 视图(view) : 存储起来的 select 语句 create view ...
- opencv + cuda编译
#获取最新代码git clone "https://github.com/opencv/opencv.git" #build目录mkdir buildcd build #使用ccm ...
- redis-cli 通过管道 --pipe 快速导入数据到redis中
最近有个需求,需要把五千万条数据批量写入redis中,方法倒是有很多种!效率最高的就是通过redis-cl管道的方式写入 一:先看看命令 cat redis.txt | redis-cli -h 12 ...
- GWAS后续分析:多基因风险评分(Polygenic Risk Score)的计算
一.什么是多基因风险评分 传统的GWAS研究只计算单个SNP位点与表型之间的关联性,再用Bonferroni校正,通过给定的阈值,筛选出显著的SNP位点. 这样会存在两个问题,第一.Bonferron ...