Created
January 5, 2017 01:39
-
-
Save liondancer/50f7e1d089984582f38029ef093e6439 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def isValidBST(root, max=sys.maxint, min=-sys.maxint): | |
""" | |
:type root: TreeNode | |
:rtype: bool | |
""" | |
if root is None: | |
return True | |
return root.val < max and root.val > min and isValidBST(root.left, max=root.val, min=min) and isValidBST(root.right, max=max, min=root.val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment