We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2d0e0cc commit eb1a5d6Copy full SHA for eb1a5d6
python/0063-unique-paths-ii.py
@@ -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