File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ # @param obstacleGrid, a list of lists of integers
3
+ # @return an integer
4
+ def uniquePathsWithObstacles (self , obstacleGrid ):
5
+ n = len (obstacleGrid )
6
+ m = len (obstacleGrid [0 ])
7
+ for i in range (n ):
8
+ for j in range (m ):
9
+ if i == 0 :
10
+ if obstacleGrid [i ][j ] == 0 :
11
+ if j == 0 or (j > 0 and obstacleGrid [i ][j - 1 ] != 0 ):
12
+ obstacleGrid [i ][j ] = 1
13
+ else :
14
+ obstacleGrid [i ][j ] = 0
15
+ elif j == 0 :
16
+ if obstacleGrid [i ][j ] == 0 :
17
+ # i must be greater that zero here
18
+ if obstacleGrid [i - 1 ][j ] != 0 :
19
+ obstacleGrid [i ][j ] = 1
20
+ else :
21
+ obstacleGrid [i ][j ] = 0
22
+ else :
23
+ if obstacleGrid [i ][j ] == 0 :
24
+ obstacleGrid [i ][j ] = (obstacleGrid [i - 1 ][j ]
25
+ + obstacleGrid [i ][j - 1 ])
26
+ else :
27
+ obstacleGrid [i ][j ] = 0
28
+ return obstacleGrid [n - 1 ][m - 1 ]
You can’t perform that action at this time.
0 commit comments