/**
 * Definition for binary tree
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public boolean isValidBST(TreeNode root) {
        //here need to use Long rather than Integer.
        //I think the only way to avoid edge cases like {MAX_INT} to handle this in recursion
        //which makes the code fairly ugly
        return this.check(root, Long.MAX_VALUE, Long.MIN_VALUE);   
    }
    
    public boolean check(TreeNode root, long root_max, long root_min) {
        if (root == null) {
            return true;
        }
        if (root.val >= root_max || root.val <= root_min) {
            return false;
        }
        return check(root.left, root.val, root_min) && check(root.right, root_max, root.val);
    }
}

@@ -1,499 +1,122 @@
-/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A    public boolean isValidBST(TreeNode root) %7B%0A        //here need to use Long rather than Integer.%0A        //I think the only way to avoid edge cases like %7BMAX_INT%7D to handle this in recursion%0A        //which makes the code fairly ugly%0A        return this.check(root, Long.MAX_VALUE, Long.MIN_VALUE);   
+public class Solution %7B%0A    public boolean isValidBST(TreeNode root) %7B%0A        return this.validate(root, null, null);
 %0A   
@@ -124,29 +124,30 @@
 %7D%0A    %0A    p
-ublic
+rivate
  boolean che
@@ -143,21 +143,24 @@
 boolean 
-check
+validate
 (TreeNod
@@ -171,33 +171,29 @@
 ot, 
-long root_max, long root_
+Integer max, Integer 
 min)
@@ -270,56 +270,111 @@
     
-if (root.val %3E= root_max %7C%7C root.val %3C= root_min
+%0A        if ((max != null && root.val %3E= max.intValue()) %7C%7C (min != null && root.val %3C= min.intValue())
 ) %7B%0A
@@ -421,20 +421,32 @@
     
-return check
+%0A        return validate
 (roo
@@ -467,21 +467,16 @@
 al, 
-root_
 min) && 
 chec
@@ -475,13 +475,16 @@
  && 
-check
+validate
 (roo
@@ -496,13 +496,8 @@
 ht, 
-root_
 max,
@@ -513,11 +513,12 @@
 );%0A    %7D
+ 
 %0A%7D%0A

Update ValidateBinarySearchTree.java