Using two `l`

and `r`

to represent the left and right boundaries for `root.val`

.

```
class Solution(object):
def isValidBST(self, root, l = float('-inf'), r = float('inf')):
"""
:type root: TreeNode
:rtype: bool
"""
return not root or (l < root.val < r and self.isValidBST(root.left, \
l, root.val) and self.isValidBST(root.right, root.val, r))
```