classSolution:defuniquePathsWithObstacles(self, obstacleGrid: List[List[int]])->int:ifnot obstacleGrid ornot obstacleGrid[0]:return0if obstacleGrid[0][0]==1:return0
m, n =len(obstacleGrid),len(obstacleGrid[0])
flag =Truefor i inrange(n):if obstacleGrid[0][i]==1:
flag =Falseif flag:
obstacleGrid[0][i]=1else:
obstacleGrid[0][i]=0
flag =Truefor i inrange(1,m):if obstacleGrid[i][0]==1:
flag =Falseif flag:
obstacleGrid[i][0]=1else:
obstacleGrid[i][0]=0for i inrange(1, m):for j inrange(1, n):if obstacleGrid[i][j]==1:
obstacleGrid[i][j]=0else:
obstacleGrid[i][j]= obstacleGrid[i-1][j]+ obstacleGrid[i][j-1]return obstacleGrid[-1][-1]