-
Notifications
You must be signed in to change notification settings - Fork 0
/
63_Unique_Paths_II.py
32 lines (30 loc) · 1013 Bytes
/
63_Unique_Paths_II.py
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
class Solution:
def uniquePathsWithObstacles(self, obstacleGrid):
"""
:type obstacleGrid: List[List[int]]
:rtype: int
"""
m,n = len(obstacleGrid),len(obstacleGrid[0])
matrix = [[0 for x in range(n)] for x in range(m)]
if(obstacleGrid[0][0] == 1):
matrix[0][0] = 0
else:
matrix[0][0] = 1
for i in range(1,m):
if(obstacleGrid[i][0] == 1):
matrix[i][0] = 0
else:
matrix[i][0] = matrix[i-1][0]
for j in range(1,n):
if(obstacleGrid[0][j] == 1):
matrix[0][j] = 0
else:
matrix[0][j] = matrix[0][j-1]
for i in range(1,m):
for j in range(1,n):
if(obstacleGrid[i][j] == 1):
matrix[i][j] = 0
else:
matrix[i][j] = matrix[i-1][j] + matrix[i][j-1]
print(matrix)
return matrix[m-1][n-1]