LeetCode Solutions/August 2022 LeetCoding Challenge/Validate Binary Search Tree.java
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isValidBST(TreeNode root) {
        return helper(root,Long.MAX_VALUE,Long.MIN_VALUE);
    }
    public boolean helper(TreeNode root,long min,long max){
        if(root == null){
            return true;
        }
        if(root.val >= min || root.val <= max){
            return false;
        }
        return helper(root.left,root.val,max) && helper(root.right,min,root.val);
    }
}