mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 08:27:30 +08:00
21 lines
342 B
Go
21 lines
342 B
Go
package leetcode
|
|
|
|
func uniquePaths(m int, n int) int {
|
|
dp := make([][]int, n)
|
|
for i := 0; i < n; i++ {
|
|
dp[i] = make([]int, m)
|
|
}
|
|
for i := 0; i < m; i++ {
|
|
dp[0][i] = 1
|
|
}
|
|
for i := 0; i < n; i++ {
|
|
dp[i][0] = 1
|
|
}
|
|
for i := 1; i < n; i++ {
|
|
for j := 1; j < m; j++ {
|
|
dp[i][j] = dp[i-1][j] + dp[i][j-1]
|
|
}
|
|
}
|
|
return dp[n-1][m-1]
|
|
}
|