LeetCode 2482. Difference Between Ones and Zeros in Row and Column in F#

URL

https://leetcode.com/problems/difference-between-ones-and-zeros-in-row-and-column/description/?envType=daily-question&envId=2023-12-14

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/problems/2482/main.fsx

let onesMinusZeros (grid: int[,]) : int[,] =
    let rows, cols = Array2D.length1 grid, Array2D.length2 grid
    let rowOnes = Array.zeroCreate rows
    let colOnes = Array.zeroCreate cols

    for i in 0 .. (rows - 1) do
        for j in 0 .. (cols - 1) do
            rowOnes.[i] <- rowOnes.[i] + grid.[i, j]
            colOnes.[j] <- colOnes.[j] + grid.[i, j]

    let ret = Array2D.zeroCreate rows cols

    for i in 0 .. (rows - 1) do
        for j in 0 .. (cols - 1) do
            let x, y = rowOnes.[i], colOnes.[j]
            ret.[i, j] <- x + y - (rows - x) - (cols - y)

    ret