-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path63.go
More file actions
35 lines (34 loc) · 806 Bytes
/
63.go
File metadata and controls
35 lines (34 loc) · 806 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
31
32
33
34
35
package main
func uniquePathsWithObstacles(obstacleGrid [][]int) int {
m := len(obstacleGrid)
n := len(obstacleGrid[0])
for i := 0; i < m; i++ {
for j := 0; j < n; j++ {
if i == 0 && j == 0 {
if obstacleGrid[i][j] == 1 {
return 0
}
obstacleGrid[i][j] = 1
} else if i == 0 {
if obstacleGrid[i][j] == 1 || obstacleGrid[i][j-1] == 0 {
obstacleGrid[i][j] = 0
} else {
obstacleGrid[i][j] = 1
}
} else if j == 0 {
if obstacleGrid[i][j] == 1 || obstacleGrid[i-1][j] == 0 {
obstacleGrid[i][j] = 0
} else {
obstacleGrid[i][j] = 1
}
} else {
if obstacleGrid[i][j] == 1 {
obstacleGrid[i][j] = 0
} else {
obstacleGrid[i][j] = obstacleGrid[i-1][j] + obstacleGrid[i][j-1]
}
}
}
}
return obstacleGrid[m-1][n-1]
}