LeetCode 121. Best Time to Buy and Sell Stock in F#

URL

https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/

Code

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

open System

let maxProfit (prices: int list) : int =
    let rec maxProfit' (prices: int list) (min: int) (ret: int) =
        match prices with
        | [] -> ret
        | h :: t -> maxProfit' t (Math.Min(min, h)) (Math.Max(ret, h - min))

    maxProfit' prices Int32.MaxValue 0