mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge pull request #364 from ChrisLin1997/feature/js-62
添加0062.不同路径Javascript版本
This commit is contained in:
@ -308,6 +308,27 @@ func uniquePaths(m int, n int) int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Javascript:
|
||||||
|
```Javascript
|
||||||
|
var uniquePaths = function(m, n) {
|
||||||
|
const dp = Array(m).fill().map(item => Array(n))
|
||||||
|
|
||||||
|
for (let i = 0; i < m; ++i) {
|
||||||
|
dp[i][0] = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < n; ++i) {
|
||||||
|
dp[0][i] = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 1; i < m; ++i) {
|
||||||
|
for (let j = 1; j < n; ++j) {
|
||||||
|
dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[m - 1][n - 1]
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user