Skip to content

Instantly share code, notes, and snippets.

@evidanary
Created June 16, 2017 21:46
Show Gist options
  • Save evidanary/25ce553798424034876b6da55b5577da to your computer and use it in GitHub Desktop.
Save evidanary/25ce553798424034876b6da55b5577da to your computer and use it in GitHub Desktop.
# Check if a binary tree is valid
class Solution
def initialize()
@prev = nil
end
def is_valid_bst(root)
return true if root.nil?
left = is_valid_bst(root.left)
return false if (@prev && (@prev >= root.val ))
@prev = root.val
right = is_valid_bst(root.right)
left && right
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment