LeetCode 2554. Maximum Number of Integers to Choose From a Range I in F#
URL
Code
let maxCount (banned: int list) (n: int) (maxSum: int) : int =
let rec maxCount' i n count sum banned =
if i > n then
count
else if Set.contains i banned then
maxCount' (i + 1) n count sum banned
else if i > sum then
count
else
maxCount' (i + 1) n (count + 1) (sum - i) banned
maxCount' 1 n 0 maxSum (Set.ofList banned)