JAVA solution SHARING


  • 0
    W

    public class Solution {
    public boolean isValidBST(TreeNode root) {
    return isBST(root, null, null);
    }
    private boolean isBST(TreeNode x, Integer min, Integer max) {
    if (x == null) return true;
    if (min != null && x.val <= min) return false;
    if (max != null && x.val >= max) return false;
    return isBST(x.left, min, x.val) && isBST(x.right, x.val, max);
    }
    }


Log in to reply
 

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