Skip to content

Commit d204a54

Browse files
Unique Path || - DP
1 parent 1e940bc commit d204a54

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Solutions/63.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
func uniquePathsWithObstacles(obstacleGrid [][]int) int {
2+
m, n := len(obstacleGrid), len(obstacleGrid[0])
3+
dp := make([][]int, m)
4+
5+
for i := 0; i < m; i++ {
6+
dp[i] = make([]int, n) // Initialize the inner slices
7+
for j := 0; j < n; j++ {
8+
if obstacleGrid[i][j] == 1 {
9+
dp[i][j] = 0
10+
} else if i == 0 && j == 0 {
11+
dp[i][j] = 1
12+
} else if i == 0 {
13+
dp[i][j] = dp[i][j-1]
14+
} else if j == 0 {
15+
dp[i][j] = dp[i-1][j]
16+
} else {
17+
dp[i][j] = dp[i-1][j] + dp[i][j-1]
18+
}
19+
}
20+
}
21+
22+
return dp[m-1][n-1]
23+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy