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 98e3b96 commit 7862bd4Copy full SHA for 7862bd4
scripts/algorithms/U/Unique Paths II/Unique Paths II.js
@@ -1,24 +1,25 @@
1
+// Runtime: 111 ms (Top 27.88%) | Memory: 42.8 MB (Top 44.48%)
2
var uniquePathsWithObstacles = function(obstacleGrid) {
3
const m = obstacleGrid.length;
4
const n = obstacleGrid[0].length;
-
5
+
6
const results = new Array(m).fill(0);
7
for (let i = 0; i < m; i++) {
8
results[i] = new Array(n).fill(0);
9
}
10
11
12
for (let j = 0; j < n; j++) {
13
if (i === 0 && j === 0) {
14
results[0][0] = obstacleGrid[0][0] ? 0 : 1;
15
} else if (!obstacleGrid[i][j]) {
16
const up = i === 0 ? 0 : results[i - 1][j];
17
const left = j === 0 ? 0 : results[i][j - 1];
18
19
results[i][j] = up + left;
- }
20
+ }
21
22
23
24
return results[m - 1][n - 1];
-}
25
+}
0 commit comments