https://leetcode.cn/problems/unique-paths-ii/
class Solution:
def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
m = len(obstacleGrid)
n = len(obstacleGrid[0])
if obstacleGrid[m - 1][n - 1] == 1 or obstacleGrid[0][0] == 1:
return 0
bq = [[0] * n for _ in range(m)]
for i in range(m):
if obstacleGrid[i][0] == 0:
bq[i][0] = 1
else:
break
for i in range(n):
if obstacleGrid[0][i] == 0:
bq[0][i] = 1
else:
break
for i in range(1, m):
for j in range(1, n):
if obstacleGrid[i][j] == 1:
continue
else:
bq[i][j] = bq[i - 1][j] + bq[i][j - 1]
return bq[m - 1][n - 1]