Skip to content

Commit 8c8c46a

Browse files
committed
add 0063
1 parent f77c92c commit 8c8c46a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

0062. Unique Paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ const uniquePaths = (m, n) => {
7676
return arr[n - 1]
7777
}
7878
// Runtime: 48 ms, faster than 94.76 % of JavaScript online submissions for Unique Paths.
79-
// Memory Usage: 33.6 MB, less than 100.00 % of JavaScript online submissions for Unique Paths.
79+
// Memory Usage: 33.6 MB, less than 100.00 % of JavaScript online submissions for Unique Paths.

0063. Unique Paths II.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,41 @@
2424
// 2. Down -> Down -> Right -> Right
2525

2626

27+
/**
28+
* @param {number[][]} obstacleGrid
29+
* @return {number}
30+
*/
31+
const uniquePathsWithObstacles = (obstacleGrid) => {
32+
let row = obstacleGrid.length
33+
let col = obstacleGrid[0].length
34+
let arr = Array(row)
35+
for (let i = 0; i < row; i++) {
36+
arr[i] = Array(col).fill(1)
37+
}
38+
for (let i = 0; i < row; i++) {
39+
for (let j = 0; j < col; j++) {
40+
if (i === 0 && obstacleGrid[i][j] === 1) {
41+
for (let k = 0; k < col; k++) {
42+
if (k >= j) {
43+
arr[0][k] = 0
44+
}
45+
}
46+
}
47+
if (j === 0 && obstacleGrid[i][j] === 1) {
48+
for (let k = 0; k < row; k++) {
49+
if (k >= i) {
50+
arr[k][0] = 0
51+
}
52+
}
53+
}
54+
if (obstacleGrid[i][j] === 1) {
55+
arr[i][j] = 0
56+
} else if (i > 0 && j > 0) {
57+
arr[i][j] = arr[i - 1][j] + arr[i][j - 1]
58+
}
59+
}
60+
}
61+
return arr[row - 1][col - 1]
62+
}
63+
// Runtime: 64 ms, faster than 43.05 % of JavaScript online submissions for Unique Paths II.
64+
// Memory Usage: 35.6 MB, less than 100.00 % of JavaScript online submissions for Unique Paths II.

0 commit comments

Comments
 (0)