Leetcode:530. 二叉搜索树的最小绝对差
2024-08-28 20:56:55
Leetcode:530. 二叉搜索树的最小绝对差
Leetcode:530. 二叉搜索树的最小绝对差
Talk is cheap . Show me the code .
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int min=INT_MAX;
TreeNode* preNode=NULL;
void DFS(TreeNode* root){
if(root==NULL) return;
DFS(root->left);
if(preNode!=NULL&&abs(root->val-preNode->val)<min) min=abs(root->val-preNode->val);
preNode=root;
DFS(root->right);
}
int getMinimumDifference(TreeNode* root) {
DFS(root);
return min;
}
};
最新文章
- 图片处理GraphicsMagick &; ImageMagick
- jquery学习笔记:获取下拉框的值和下拉框的txt
- CentOS6.5 FTP配置
- Libsvm:脚本(subset.py、grid.py、checkdata.py) | MATLAB/OCTAVE interface | Python interface
- HIVE自定义函数 UDF
- Jmeter 发送json{Jfinal 接口req rsp均为json}
- tf–idf算法解释及其python代码实现(上)
- eclipse svn2.0.0插件 手动安装方法
- 思考的工作方式——计划经济or市场经济
- 百度地图JavaScript API经纬度查询-MAP
- centos7 fortune+cowsay+lolcat美化初始终端
- Codeforces Round #545 Div. 1自闭记
- spring mvc读取properties资源文件夹中文乱码问题
- c#泛型TryParse类型转换
- 发布webservice之后调用不通
- UI5-学习篇-7-Postman测试SAP OData Services
- kubectl error: The connection to the server localhost:8080 was refused
- reportng代替testng的默认报告——pom设置
- mysql 变量名称不能与表字段一致
- 2018.08.10 atcoder Median Sum(01背包)
热门文章
- 性能工具之stress工具使用教程(带源码说明)
- 【题解】codeforces 8c Looking for Order 状压dp
- Mysql优化(出自官方文档) - 第十二篇(优化锁操作篇)
- Vue(8)列表渲染v-for
- VueX理解
- This application failed to start because no Qt platform plugin could be initialized
- .obj : error LNK2019: 无法解析的外部符号
- [网络编程]mqtt概念&;数据包
- Linux:Linux更新yum方法
- @Valid 注解的使用