```
def isValidBST(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
return self.dfs(root, -float('inf'), float('inf'))
def dfs(self, root, l, r):
if not root:
return True
if root.val <= l or root.val >= r:
return False
return self.dfs(root.left, l, root.val) and self.dfs(root.right, root.val, r)
```