Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created July 12, 2019 03:12
Show Gist options
  • Save jubishop/40d199bf1c3a22f566189ff6f495319c to your computer and use it in GitHub Desktop.
Save jubishop/40d199bf1c3a22f566189ff6f495319c to your computer and use it in GitHub Desktop.
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