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); } }

@lqianudel.edu It is not a requirement in the question that the minimum difference between two nodes has to be between two adjacent nodes. The question specifies "any" two different nodes. So, in order approach is not at all a dumb approach.