forked from yingl/LintCodeInPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunique_paths_ii.py
More file actions
23 lines (22 loc) · 852 Bytes
/
unique_paths_ii.py
File metadata and controls
23 lines (22 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding: utf-8 -*-
class Solution:
"""
@param obstacleGrid: An list of lists of integers
@return: An integer
"""
def uniquePathsWithObstacles(self, obstacleGrid):
rows = len(obstacleGrid)
cols = len(obstacleGrid[0])
paths = [[1 for i in xrange(cols)] for j in xrange(rows)]
for i in xrange(rows):
for j in xrange(cols):
if obstacleGrid[i][j] == 1:
paths[i][j] = 0
else:
if (i >= 1) and (j < 1):
paths[i][j] = paths[i - 1][j]
elif (i < 1) and (j >= 1):
paths[i][j] = paths[i][j - 1]
elif (i >= 1) and (j >= 1):
paths[i][j] = paths[i - 1][j] + paths[i][j - 1]
return paths[rows - 1][cols - 1]