mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
添加0063.不同路径II Javascript版本
This commit is contained in:
@ -279,6 +279,30 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int {
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Javascript
|
||||||
|
``` Javascript
|
||||||
|
var uniquePathsWithObstacles = function(obstacleGrid) {
|
||||||
|
const m = obstacleGrid.length
|
||||||
|
const n = obstacleGrid[0].length
|
||||||
|
const dp = Array(m).fill().map(item => Array(n).fill(0))
|
||||||
|
|
||||||
|
for (let i = 0; i < m && obstacleGrid[i][0] === 0; ++i) {
|
||||||
|
dp[i][0] = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < n && obstacleGrid[0][i] === 0; ++i) {
|
||||||
|
dp[0][i] = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 1; i < m; ++i) {
|
||||||
|
for (let j = 1; j < n; ++j) {
|
||||||
|
dp[i][j] = obstacleGrid[i][j] === 1 ? 0 : dp[i - 1][j] + dp[i][j - 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dp[m - 1][n - 1]
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user