LeetCode 860. Lemonade Change in F#

URL

https://leetcode.com/problems/lemonade-change/description/?envType=daily-question&envId=2024-08-15

Code

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

let lemonadeChange (bills: int list) : bool =
    let rec lemonadeChange' bills fives tens =
        match bills with
        | [] -> true
        | h :: t ->
            match h with
            | 5 -> lemonadeChange' t (fives + 1) tens
            | 10 ->
                if fives < 1 then
                    false
                else
                    lemonadeChange' t (fives - 1) (tens + 1)
            | _ ->
                if fives >= 1 && tens >= 1 then
                    lemonadeChange' t (fives - 1) (tens - 1)
                elif fives >= 3 then
                    lemonadeChange' t (fives - 3) tens
                else
                    false

    lemonadeChange' bills 0 0