File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ # Runtime: 40 ms, faster than 75.14% of Python3 online submissions for Unique Paths II.
2+ # Difficulty: Medium
3+
4+ class Solution :
5+ def uniquePathsWithObstacles (self , obstacleGrid ):
6+ """
7+ :type obstacleGrid: List[List[int]]
8+ :rtype: int
9+ """
10+ dp_grid = [[0 for i in range (len (obstacleGrid [0 ]))]
11+ for j in range (len (obstacleGrid ))]
12+ dp_grid [len (dp_grid )- 1 ][len (dp_grid [0 ])- 1 ] = 1
13+
14+ for row in range (len (obstacleGrid )- 1 , - 1 , - 1 ):
15+ for col in range (len (obstacleGrid [row ])- 1 , - 1 , - 1 ):
16+ if obstacleGrid [row ][col ] == 1 :
17+ dp_grid [row ][col ] = 0
18+ continue
19+ if row + 1 < len (obstacleGrid ):
20+ dp_grid [row ][col ] += dp_grid [row + 1 ][col ]
21+ if col + 1 < len (obstacleGrid [row ]):
22+ dp_grid [row ][col ] += dp_grid [row ][col + 1 ]
23+ return dp_grid [0 ][0 ]
You can’t perform that action at this time.
0 commit comments