MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / uniquePathsWithObstacles

Method uniquePathsWithObstacles

DP/UniquePathII.py:84–113  ·  view source on GitHub ↗

:type obstacleGrid: List[List[int]] :rtype: int

(self, _map)

Source from the content-addressed store, hash-verified

82class Solution(object):
83
84 def uniquePathsWithObstacles(self, _map):
85 """
86 :type obstacleGrid: List[List[int]]
87 :rtype: int
88 """
89
90 if _map[0][0] == 1:
91 return 0
92
93 if _map[-1][-1] == 1:
94 return 0
95
96
97 n, m = len(_map), len(_map[0])
98
99 for i in range(n):
100 for j in range(m):
101 if _map[i][j] == 1:
102 _map[i][j] = 'x'
103 continue
104
105 x = _map[i-1][j] if i - 1 >= 0 and _map[i-1][j] != 'x' else 0
106 y = _map[i][j-1] if j - 1 >= 0 and _map[i][j-1] != 'x' else 0
107
108 if x + y != 0:
109 _map[i][j] = x + y
110 elif i + j == 0:
111 _map[i][j] = 1
112
113 return _map[n-1][m-1]
114
115 # def uniquePathsWithObstacles(self, _map):
116 # """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected