#98.Validate Binary Search Tree [LeetCode Grind 75 in Java]

[Problem Link] https://leetcode.com/problems/validate-binary-search-tree/

class Solution {

    public boolean isValid(TreeNode root, long minLimit, long maxLimit){
        if(root == null) return true;
        if(root.val <= minLimit || root.val >= maxLimit) return false;
        return (isValid(root.left, minLimit, root.val) && isValid(root.right, root.val, maxLimit));
    }

    public boolean isValidBST(TreeNode root) {
        return isValid(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }
}