LeetCode 1475. Final Prices With a Special Discount in a Shop in F#

URL

https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/description/?envType=daily-question&envId=2024-12-18

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202412/final_prices_with_a_special_discount_in_a_shop/main.fsx

let finalPrices (prices: int list) : int list =
    let rec finalPrices' prices acc =
        match prices with
        | [] -> List.rev acc
        | h :: t ->
            match List.tryFind ((>=) h) t with
            | Some(v) -> finalPrices' t ((h - v) :: acc)
            | None -> finalPrices' t (h :: acc)

    finalPrices' prices []