Skip to content

Commit eb1a5d6

Browse files
authored
create: 0063-unique-paths-ii.py
1 parent 2d0e0cc commit eb1a5d6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: python/0063-unique-paths-ii.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def uniquePathsWithObstacles(self, mat: List[List[int]]) -> int:
3+
m = len(mat)
4+
n = len(mat[0])
5+
prev = [0 for _ in range(n)]
6+
7+
for i in range(m):
8+
curr = [0 for _ in range(n)]
9+
for j in range(n):
10+
if mat[i][j] == 1:
11+
curr[j] = 0
12+
elif i == 0 and j == 0:
13+
curr[j] = 1
14+
else:
15+
up = 0
16+
left = 0
17+
if i>0:
18+
up = prev[j]
19+
if j > 0:
20+
left = curr[j-1]
21+
curr[j] = up + left
22+
prev = curr
23+
return prev[n-1]

0 commit comments

Comments
 (0)