Ruby Recursive Solution


  • 0
    M
    def is_valid_bst(root, min = -Float::INFINITY, max = Float::INFINITY)
        return true unless root
        if root.val <= min || root.val >= max
            return false
        else
            is_valid_bst(root.left, min, root.val) && is_valid_bst(root.right, root.val, max)
        end
    end
    

  • 0
    S

    didn't know you're allowed to modify the preset paramaters


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.