```
public class Solution {
public boolean isValidBST(TreeNode root) {
return isValidBST_dfs(root, Long.MIN_VALUE, Long.MAX_VALUE);
}
private boolean isValidBST_dfs(TreeNode root, long min, long max){
if(root == null) return true;
if(root.val>= max || root.val<=min) return false;
boolean left = isValidBST_dfs(root.left, min, root.val);
boolean right = isValidBST_dfs(root.right, root.val, max);
return left&right;
}
}
```