Skip to content

Commit

Permalink
Merge pull request youngyangyang04#339 from nmydt/patch-5
Browse files Browse the repository at this point in the history
添加 0530.二叉搜索树的最小绝对差 java版本
  • Loading branch information
youngyangyang04 authored Jun 7, 2021
2 parents 64ce587 + 2499b61 commit a4b7399
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion problems/0530.二叉搜索树的最小绝对差.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,30 @@ public:
Java:
递归
```java
class Solution {
TreeNode pre;// 记录上一个遍历的结点
int result = Integer.MAX_VALUE;
public int getMinimumDifference(TreeNode root) {
if(root==null)return 0;
traversal(root);
return result;
}
public void traversal(TreeNode root){
if(root==null)return;
//左
traversal(root.left);
//中
if(pre!=null){
result = Math.min(result,root.val-pre.val);
}
pre = root;
//右
traversal(root.right);
}
}
```
```Java
class Solution {
TreeNode pre;// 记录上一个遍历的结点
Expand Down

0 comments on commit a4b7399

Please sign in to comment.