public class erchashoushuo {
static class TreeNode{
int val;
TreeNode left;
TreeNode right;
TreeNode root;
TreeNode(){};
TreeNode(int val) { this.val = val; }
TreeNode(int val, TreeNode left, TreeNode right){
this.val = val;
this.left = left;
this.right = right;
}
public void setLeft(TreeNode left){
this.left=left;
}
public void setRight(TreeNode right){
this.right=right;
}
public void setRoot(TreeNode root){
this.root=root;
}
}
public boolean isValidBST(TreeNode root) {
return isValidBST(root, Long.MIN_VALUE, Long.MAX_VALUE);
}
public boolean isValidBST(TreeNode node, long lower, long upper) {
if (node == null) {
return true;
}
if (node.val <= lower || node.val >= upper) {
return false;
}
return isValidBST(node.left, lower, node.val) && isValidBST(node.right, node.val, upper);
}
public static void main(String[] args) {
TreeNode treeNode =new TreeNode();
TreeNode node1=new TreeNode(1,null,null);
TreeNode node2=new TreeNode(3,null,null);
TreeNode root=new TreeNode(2, node1, node2);
erchashoushuo er=new erchashoushuo();
boolean k=er.isValidBST(root);
System.out.println(k);
}
}