latest java avoid Integer.MAX_VALUE solution


  • 0
    W
    public boolean isValidBST(TreeNode root) {
            
            return valid(root, null, null);
        }
        boolean valid (TreeNode root, Integer max, Integer min) {
            if (root == null) {
                return true;
            }
            
            if (( max == null || root.val < max) && (min == null || root.val > min )) {
                return valid(root.left, root.val, min) && valid(root.right, max, root.val);
            } else {
                return false;
            }
        }

Log in to reply
 

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