Minimum Absolute Difference in BST LeetCode solution in Java
1class Solution {2int prev = Integer.MAX_VALUE;3int ans = Integer.MAX_VALUE;45public int getMinimumDifference(TreeNode root) {6inOrder(root);7return ans;8}910public void inOrder(TreeNode root) {11if (root.left != null) inOrder(root.left);12ans = Math.min(ans, Math.abs(root.val - prev));13prev = root.val;14if (root.right != null) inOrder(root.right);15}16}