contains category wise problems(data structures, competitive) of popular platforms.
View the Project on GitHub mayankdutta/category-wise-problems
783. Minimum Distance Between BST Nodes
class Solution {
int ans;
TreeNode prev;
public void inorder(TreeNode root) {
if (root == null)
return;
inorder(root.left);
if (prev != null)
ans = Math.min(ans, Math.abs(root.val - prev.val));
prev = root;
inorder(root.right);
}
public int minDiffInBST(TreeNode root) {
prev = null;
ans = Integer.MAX_VALUE;
inorder(root);
return ans;
}
}