LeetCode 119. Pascal's Triangle II in F#

URL

Pascal's Triangle II - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202310/pascals-triangle-2/main.fsx

let getRow (rowIndex: int) : int[] =
    let rec getRow' i rowIndex (prev: int[]) =
        if i > rowIndex then
            prev
        else
            let cur =
                Array.init (i + 1) (fun j ->
                    if j = 0 then prev.[0]
                    elif j = i then prev.[j - 1]
                    else prev.[j - 1] + prev.[j])

            getRow' (i + 1) rowIndex cur

    getRow' 1 rowIndex [| 1 |]