LeetCode 1346. Check If N and Its Double Exist in F#

URL

Check If N and Its Double Exist - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202412/check_if_n_and_its_double_exist/main.fsx

let checkIfExist (arr: int list) : bool =
    let h =
        arr
        |> List.indexed
        |> List.fold
            (fun acc (i, n) ->
                match Map.tryFind n acc with
                | Some(v) -> Map.add n (i :: v) acc
                | None -> Map.add n [ i ] acc)
            Map.empty

    arr
    |> List.indexed
    |> List.exists (fun (i, n) ->
        match Map.tryFind (2 * n) h with
        | None -> false
        | Some(v) -> List.exists (fun j -> i <> j) v)