-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path63.go
More file actions
30 lines (27 loc) · 756 Bytes
/
Copy path63.go
File metadata and controls
30 lines (27 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
func uniquePathsWithObstacles(obstacleGrid [][]int) int {
m := len(obstacleGrid)
n := len(obstacleGrid[0])
dp := make([][]int, m)
for i := 0; i < m; i ++ {
dp[i] = make([]int, n)
}
for i := m - 1; i >= 0; i -- {
for j := n - 1; j >= 0; j -- {
if obstacleGrid[i][j] == 1 {
dp[i][j] = 0
continue
}
if i == m - 1 && j == n - 1 {
dp[i][j] = 1
} else if i == m - 1 {
dp[i][j] = dp[i][j + 1]
} else if j == n - 1 {
dp[i][j] = dp[i + 1][j]
} else {
dp[i][j] = dp[i + 1][j] + dp[i][j + 1]
}
}
}
return dp[0][0]
}