Minimum Absolute Difference in BST LeetCode solution in Java

1
class Solution {
2
int prev = Integer.MAX_VALUE;
3
int ans = Integer.MAX_VALUE;
4

5
public int getMinimumDifference(TreeNode root) {
6
inOrder(root);
7
return ans;
8
}
9

10
public void inOrder(TreeNode root) {
11
if (root.left != null) inOrder(root.left);
12
ans = Math.min(ans, Math.abs(root.val - prev));
13
prev = root.val;
14
if (root.right != null) inOrder(root.right);
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0