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
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