LeetCode 3223. Minimum Length of String After Operations in F#

URL

https://leetcode.com/problems/minimum-length-of-string-after-operations/description/?envType=daily-question&envId=2025-01-13

Code

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

let minimumLength (s: string) : int =
    s
    |> Seq.fold
        (fun (acc: int[]) c ->
            let index = int c - int 'a'
            acc.[index] <- acc.[index] + 1
            acc)
        (Array.zeroCreate 26)
    |> Array.fold
        (fun acc n ->
            if n = 0 then acc
            elif n % 2 = 1 then acc + 1
            else acc + 2)
        0