剑指 Offer II 098. 路径的数目
2022-08-17 本文已影响0人
邦_
重复题 = =。。
func uniquePaths(_ m: Int, _ n: Int) -> Int {
let temp = Array.init(repeating: 0, count: n)
var dp = Array.init(repeating: temp, count: m)
for i in 0..<m {
for j in 0..<n {
if i == 0 || j == 0 {
dp[i][j] = 1
} else{
dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
}
}
}
return dp[m - 1][n - 1]
}