1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int row = obstacleGrid.length, column = obstacleGrid[0].length; int[][] path = new int[row][column]; path[0][0] = 1; for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { if (obstacleGrid[i][j] == 1) { path[i][j] = 0; } else { if (i >= 1) { path[i][j] += path[i - 1][j]; } if (j >= 1) { path[i][j] += path[i][j - 1]; } } } } return path[row - 1][column - 1]; } }
|