Shohei Yoshida
Shohei Yoshida's Blog

Shohei Yoshida's Blog

LeetCode 62. Unique Paths in F#

Shohei Yoshida's photo
Shohei Yoshida
·Aug 1, 2022·

1 min read

URL

leetcode.com/problems/unique-paths

Code

github.com/syohex/dotnet-study/blob/master/..

let uniquePaths (m: int) (n: int) : int =
    let dp = Array2D.zeroCreate m n
    dp.[0, 0] <- 1

    for i in 0 .. (m - 1) do
        for j in 0 .. (n - 1) do
            if i <> 0 then
                dp.[i, j] <- dp.[i, j] + dp.[i - 1, j]

            if j <> 0 then
                dp.[i, j] <- dp.[i, j] + dp.[i, j - 1]

    dp.[m - 1, n - 1]
 
Share this