```
class Solution:
# @param root, a tree node
# @return a boolean
def isValidBST(self, root):
if root == None:
return True
def valid(root, maximum, minimum):
if root.val >= maximum or root.val <= minimum:
return False
left, right = True, True
if root.left != None:
left = valid(root.left, root.val, minimum)
if root.right != None:
right = valid(root.right, maximum, root.val)
return left and right
return valid(root, float("inf"), float("-inf"))
```