var isValidBST = function(root) {
return helper(root, null, null);
}
function helper(node, low, high) {
if (node === null) return true;
const val = node.val;
if ((low !== null && val <= low) || (high !== null && val >= high))
return false;
return helper(node.right, val, high) && helper(node.left, low, val);
}
def is_valid_bst(root)
return is_valid(root,nil,nil)
end
def is_valid(root, min, max)
return !root || ((!max || root.val< max) && (! min || root.val >min) && is_valid(root.left,min,root.val) && is_valid(root.right,root.val,max))
end