We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 282a143 commit b36f8f1Copy full SHA for b36f8f1
63.不同路径 II.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * @param {number[][]} obstacleGrid
3
+ * @return {number}
4
+ */
5
+var uniquePathsWithObstacles = function(obstacleGrid) {
6
+ const dp = [Math.abs(obstacleGrid[0][0] - 1)];
7
+ for (let i = 0; i < obstacleGrid.length; i++) {
8
+ for (let j = 0; j < obstacleGrid[i].length; j++) {
9
+ if (!obstacleGrid[i] || obstacleGrid[i][j] === 1) {
10
+ dp[j] = 0;
11
+ } else if (!(i === 0 && j === 0)) {
12
+ dp[j] = (obstacleGrid[i - 1] && obstacleGrid[i - 1][j] === 0 ? dp[j] : 0) + (obstacleGrid[i][j - 1] === 0 ? dp[j - 1] : 0);
13
+ }
14
15
16
+ return dp[obstacleGrid[0].length - 1];
17
+};
18
+
19
+console.log(uniquePathsWithObstacles([[1]]));
0 commit comments