Minimum Distance Between BST Nodes


public int minDiffInBST(TreeNode root) { if(root == null ){ return Integer.MAX_VALUE; } ArrayList<Integer> l = new ArrayList<>(); getInorder(root,l); int diff = Integer.MAX_VALUE; for(int i=1;i<l.size();i++){ diff = Math.min(diff,Math.abs(l.get(i1)  l.get(i))); } return diff; } public void getInorder(TreeNode root,ArrayList<Integer> l) { if(root!=null){ getInorder(root.left,l); l.add(root.val); getInorder(root.right,l); } }