Fancy 1 liner that got accepted


  • 0
    J

    public class Solution {

    public boolean isValidBST(TreeNode root) {
        return isValidBst(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }
    
    private boolean isValidBst(TreeNode root, long min, long max){
        return (root == null) || (min < root.val && max > root.val && isValidBst(root.left, min, root.val) && isValidBst(root.right, root.val, max));
    }
    

    }


Log in to reply
 

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