1. class Solution:
    2. def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
    3. if not obstacleGrid:
    4. return 0
    5. m = len(obstacleGrid)
    6. n = len(obstacleGrid[0])
    7. result = [[0] * (n + 1) for _ in range(m + 1)]
    8. result[0][1] = 1
    9. for i in range(1, m + 1):
    10. for j in range(1, n + 1):
    11. if obstacleGrid[i-1][j-1] == 0:
    12. result[i][j] = result[i-1][j] + result[i][j-1]
    13. return result[-1][-1]