We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5804d5c commit f3dbfdfCopy full SHA for f3dbfdf
Unique Paths II/Unique_Paths_II.py
@@ -0,0 +1,30 @@
1
+# 动态规划
2
+# 36ms 99.37%
3
+class Solution:
4
+ def uniquePathsWithObstacles(self, obstacleGrid):
5
+ """
6
+ :type obstacleGrid: List[List[int]]
7
+ :rtype: int
8
9
+ m, n = len(obstacleGrid), len(obstacleGrid[0])
10
+ if m is 0 or n is 0 or obstacleGrid[0][0] is 1:
11
+ return 0
12
+
13
+ score = [[0 for j in range(n)] for i in range(m)]
14
+ for i in range(1, m):
15
+ if 1 in [row[0] for row in obstacleGrid[:i + 1]]:
16
+ score[i][0] = 0
17
+ else:
18
+ score[i][0] = 1
19
+ for j in range(n):
20
+ if 1 in obstacleGrid[0][:j + 1]:
21
+ score[0][j] = 0
22
23
+ score[0][j] = 1
24
25
+ for j in range(1, n):
26
+ if obstacleGrid[i][j] is 1:
27
+ score[i][j] = 0
28
29
+ score[i][j] = score[i-1][j] + score[i][j-1]
30
+ return score[-1][-1]
0 commit comments