LeetCode 1207. Unique Number of Occurrences in F#

URL

https://leetcode.com/problems/unique-number-of-occurrences/description/

Code

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

let uniqueOccurences (arr: int list) : bool =
    let rec toFreq arr acc =
        match arr with
        | [] -> acc
        | h :: t ->
            let v = 1 + (Map.tryFind h acc |> Option.defaultValue 0)
            toFreq t (Map.add h (v + 1) acc)

    let rec uniqueOccurences' vs visited =
        match vs with
        | [] -> true
        | h :: t ->
            if Set.contains h visited then
                false
            else
                uniqueOccurences' t (Set.add h visited)

    let freq = toFreq arr Map.empty
    let vs = Map.values freq |> Seq.toList
    uniqueOccurences' vs Set.empty