Share Short Java Solution. Believe many guys change Integer.Min to Long.Min after first run XD


  • 2
    K
    public class Solution{
        public boolean isValidBST(TreeNode root) {
            return helper(Long.MIN_VALUE,Long.MAX_VALUE, root);
        }
    	private boolean helper(long minValue, long maxValue, TreeNode root) {
    		if (root == null)
    			return true;
    		return minValue < root.val && root.val < maxValue && helper(minValue,root.val,root.left) && helper(root.val,maxValue,root.right);
    	}
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.