LeetCode 1323. Maximum 69 Number in F#

URL

leetcode.com/problems/maximum-69-number

Code

github.com/syohex/dotnet-study/blob/master/..

let maximum69Number (num: int) : int =
    let rec toDigits n acc =
        if n <= 0 then
            acc
        else
            toDigits (n / 10) ((n % 10) :: acc)

    toDigits num []
    |> List.fold
        (fun (sum, ok) n ->
            if ok || n = 9 then
                sum * 10 + n, ok
            else
                sum * 10 + 9, true)
        (0, false)
    |> fst