Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

LeetCode 1207. Unique Number of Occurrences in F#

Shohei Yoshida's photo
Shohei Yoshida
·Nov 30, 2022·

1 min read

URL

leetcode.com/problems/unique-number-of-occu..

Code

github.com/syohex/dotnet-study/blob/master/..

let uniqueOccurences (arr: int list) : bool =
    arr
    |> List.fold
        (fun acc n ->
            match Map.tryFind n acc with
            | Some (v) -> Map.add n (v + 1) acc
            | None -> Map.add n 1 acc)
        Map.empty
    |> Map.values
    |> Seq.fold
        (fun acc n ->
            match Map.tryFind n acc with
            | Some (v) -> Map.add n (v + 1) acc
            | None -> Map.add n 1 acc)
        Map.empty
    |> Map.forall (fun _ v -> v = 1)
 
Share this