解题思路
动态规划
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
int R = obstacleGrid.length;
int C = obstacleGrid[0].length;
//特判
if (obstacleGrid[0][0] == 1)
return 0;
obstacleGrid[0][0] = 1;
//对第一列进行判断
for (int i = 1;i < R;i++){
obstacleGrid[i][0] = (obstacleGrid[i][0] == 0 && obstacleGrid[i-1][0] == 1) ?1:0;
}
//对第一行进行判断
for(int j = 1;j < C;j++){
obstacleGrid[0][j] = (obstacleGrid[0][j] == 0 && obstacleGrid[0][j-1] == 1) ? 1:0;
}
for (int i = 1;i < R;i++){
for (int j = 1;j < C;j++){
if (obstacleGrid[i][j] == 0)
obstacleGrid[i][j] = obstacleGrid[i-1][j] + obstacleGrid[i][j-1];
else
obstacleGrid[i][j] = 0;
}
}
return obstacleGrid[R-1][C-1];
}