Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

LeetCode 1833. Maximum Ice Cream Bars in F#

Shohei Yoshida's photo
Shohei Yoshida
·Jan 6, 2023·

1 min read

URL

Maximum Ice Cream Bars - LeetCode

Code

dotnet-study/main.fsx at master · syohex/dotnet-study · GitHub

let maxIceCream (costs: int list) (coins: int) : int =
    let rec maxIceCream' i sum costs coins =
        match costs with
        | [] -> i
        | h :: t ->
            let sum' = sum + h

            if sum' > coins then
                i
            else
                maxIceCream' (i + 1) sum' t coins

    maxIceCream' 0 0 (costs |> List.sort) coins
 
Share this