LeetCode 387. First Unique Character in a String in F#

URL

https://leetcode.com/problems/first-unique-character-in-a-string/description/?envType=daily-question&envId=2024-02-05

Code

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

let firstUniqueChar (s: string) : int =
    let m =
        s
        |> Seq.indexed
        |> Seq.fold
            (fun acc (i, c) ->
                match Map.tryFind c acc with
                | None -> Map.add c i acc
                | Some(v) -> Map.add c -1 acc)
            Map.empty
        |> Map.values
        |> Seq.filter (fun n -> n >= 0)

    if Seq.isEmpty m then -1 else Seq.min m