Created
July 12, 2019 03:12
-
-
Save jubishop/40d199bf1c3a22f566189ff6f495319c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require_relative 'jubilib/binary_tree' | |
def is_valid_bst(node, min = -Float::INFINITY, max = Float::INFINITY) | |
return true if node.nil? | |
return false unless node.val > min and node.val < max | |
return (is_valid_bst(node.left, min, [max, node.val].min) and | |
is_valid_bst(node.right, [min, node.val].max, max)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment