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;
}
};

最新文章

  1. 图片处理GraphicsMagick &amp; ImageMagick
  2. jquery学习笔记:获取下拉框的值和下拉框的txt
  3. CentOS6.5 FTP配置
  4. Libsvm:脚本(subset.py、grid.py、checkdata.py) | MATLAB/OCTAVE interface | Python interface
  5. HIVE自定义函数 UDF
  6. Jmeter 发送json{Jfinal 接口req rsp均为json}
  7. tf–idf算法解释及其python代码实现(上)
  8. eclipse svn2.0.0插件 手动安装方法
  9. 思考的工作方式——计划经济or市场经济
  10. 百度地图JavaScript API经纬度查询-MAP
  11. centos7 fortune+cowsay+lolcat美化初始终端
  12. Codeforces Round #545 Div. 1自闭记
  13. spring mvc读取properties资源文件夹中文乱码问题
  14. c#泛型TryParse类型转换
  15. 发布webservice之后调用不通
  16. UI5-学习篇-7-Postman测试SAP OData Services
  17. kubectl error: The connection to the server localhost:8080 was refused
  18. reportng代替testng的默认报告——pom设置
  19. mysql 变量名称不能与表字段一致
  20. 2018.08.10 atcoder Median Sum(01背包)

热门文章

  1. 性能工具之stress工具使用教程(带源码说明)
  2. 【题解】codeforces 8c Looking for Order 状压dp
  3. Mysql优化(出自官方文档) - 第十二篇(优化锁操作篇)
  4. Vue(8)列表渲染v-for
  5. VueX理解
  6. This application failed to start because no Qt platform plugin could be initialized
  7. .obj : error LNK2019: 无法解析的外部符号
  8. [网络编程]mqtt概念&amp;数据包
  9. Linux:Linux更新yum方法
  10. @Valid 注解的使用