LeetCode 2559. Count Vowel Strings in Ranges in F#

URL

https://leetcode.com/problems/count-vowel-strings-in-ranges/description/?envType=daily-question&envId=2025-01-02

Code

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

let vowelStrings (words: string list) (queries: (int * int) list) : int list =
    let isVowel c =
        match c with
        | 'a'
        | 'e'
        | 'i'
        | 'o'
        | 'u' -> true
        | _ -> false

    let acc =
        words
        |> List.fold
            (fun (acc, prev) w ->
                let s, e = Seq.head w, Seq.last w

                if isVowel s && isVowel e then
                    (prev + 1) :: acc, prev + 1
                else
                    prev :: acc, prev)
            ([ 0 ], 0)
        |> fst
        |> List.rev
        |> List.toArray

    queries
    |> List.fold (fun ret (l, r) -> acc.[r + 1] - acc.[l] :: ret) []
    |> List.rev