Skip to content

Instantly share code, notes, and snippets.

@liondancer
Created January 5, 2017 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liondancer/50f7e1d089984582f38029ef093e6439 to your computer and use it in GitHub Desktop.
Save liondancer/50f7e1d089984582f38029ef093e6439 to your computer and use it in GitHub Desktop.
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