Make use of the property of BST that value of nodes is bounded by their "previous" and "next" node.

Edit: Thanks to Stefan pointing out a small bug. Previous code would fail when testing [2147483647, 2147483646].

Now Long.MAX_VALUE/MIN_VALUE is used to mark the INF.

```
long minDiff = Long.MAX_VALUE;
public int getMinimumDifference(TreeNode root) {
helper(root,Long.MIN_VALUE,Long.MAX_VALUE);
return (int)minDiff;
}
private void helper(TreeNode curr, long lb, long rb){
if(curr==null) return;
if(lb!=Long.MIN_VALUE){
minDiff = Math.min(minDiff,curr.val - lb);
}
if(rb!=Long.MAX_VALUE){
minDiff = Math.min(minDiff,rb - curr.val);
}
helper(curr.left,lb,curr.val);
helper(curr.right,curr.val,rb);
}
```