We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 64ce587 + 2499b61 commit a4b7399Copy full SHA for a4b7399
problems/0530.二叉搜索树的最小绝对差.md
@@ -151,7 +151,30 @@ public:
151
152
153
Java:
154
-
+递归
155
+```java
156
+class Solution {
157
+ TreeNode pre;// 记录上一个遍历的结点
158
+ int result = Integer.MAX_VALUE;
159
+ public int getMinimumDifference(TreeNode root) {
160
+ if(root==null)return 0;
161
+ traversal(root);
162
+ return result;
163
+ }
164
+ public void traversal(TreeNode root){
165
+ if(root==null)return;
166
+ //左
167
+ traversal(root.left);
168
+ //中
169
+ if(pre!=null){
170
+ result = Math.min(result,root.val-pre.val);
171
172
+ pre = root;
173
+ //右
174
+ traversal(root.right);
175
176
+}
177
+```
178
```Java
179
class Solution {
180
TreeNode pre;// 记录上一个遍历的结点
0 commit comments