Skip to content

Latest commit

 

History

History
26 lines (25 loc) · 578 Bytes

File metadata and controls

26 lines (25 loc) · 578 Bytes
class Solution {
    int min=Integer.MAX_VALUE;
    public int minDiffInBST(TreeNode root) {
        getMin(root);
        return min;
    }
    TreeNode lastnode;
    /**
     * @return the min
     */
    public void getMin(TreeNode root) {
        if(root==null){
            return;
        }
        getMin(root.left);
        if(lastnode!=null){
            min=Math.min(min,root.val-lastnode.val);
        }
        lastnode=root;
        getMin(root.right);
        
    }
}