Skip to content

Commit

Permalink
create: 0063-unique-paths-ii.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaan6674 authored Dec 30, 2022
1 parent 2d0e0cc commit eb1a5d6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions python/0063-unique-paths-ii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:
def uniquePathsWithObstacles(self, mat: List[List[int]]) -> int:
m = len(mat)
n = len(mat[0])
prev = [0 for _ in range(n)]

for i in range(m):
curr = [0 for _ in range(n)]
for j in range(n):
if mat[i][j] == 1:
curr[j] = 0
elif i == 0 and j == 0:
curr[j] = 1
else:
up = 0
left = 0
if i>0:
up = prev[j]
if j > 0:
left = curr[j-1]
curr[j] = up + left
prev = curr
return prev[n-1]

0 comments on commit eb1a5d6

Please sign in to comment.