LeetCode 2022. Convert 1D Array Into 2D Array in F#

URL

2022. Convert 1D Array Into 2D Array

Code

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

let construct2DArray (original: int list) (m: int) (n: int) : int[,] =
    let rec construct2DArray' original (acc: int[,]) =
        match original with
        | [] -> acc
        | (i, h) :: t ->
            acc.[i / n, i % n] <- h
            construct2DArray' t acc

    if List.length original <> m * n then
        Array2D.zeroCreate 0 0
    else
        let acc = Array2D.zeroCreate m n
        construct2DArray' (List.indexed original) acc