LeetCode 2352. Equal Row and Column Pairs in F#
URL
Equal Row and Column Pairs - LeetCode
Code
https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/2352/main.fsx
let equalPairs (grid: int[,]) : int =
let n = Array2D.length1 grid
let rows =
seq { 0 .. (n - 1) }
|> Seq.map (fun i -> grid.[i, *] |> Array.toList)
|> Seq.toList
let cols =
seq { 0 .. (n - 1) }
|> Seq.map (fun i -> grid.[*, i] |> Array.toList)
|> Seq.toList
rows
|> List.fold (fun acc row -> acc + (cols |> List.filter (fun col -> row = col) |> List.length)) 0