LeetCode 1684. Count the Number of Consistent Strings in F#

URL

https://leetcode.com/problems/count-the-number-of-consistent-strings/description/?envType=daily-question&envId=2024-09-12

Code

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

let countConsistentStrings (allowed: string) (words: string list) : int =
    let allowed =
        allowed
        |> Seq.fold
            (fun (acc: bool[]) c ->
                acc.[int c - int 'a'] <- true
                acc)
            (Array.zeroCreate 26)

    let isConsistent word =
        word |> Seq.forall (fun c -> allowed.[int c - int 'a'])

    words |> List.filter isConsistent |> List.length