There is one obstacle in the middle of a 3x3 grid as illustrated below.
[
[0,0,0],
[0,1,0],
[0,0,0]
]
1 public class Solution { 2 public int uniquePathsWithObstacles(int[][] obstacleGrid) { 3 int len = obstacleGrid.length; 4 if(len==0) return 0; 5 int len2 = obstacleGrid[0].length; 6 if(obstacleGrid[0][0]==1) return 0; 7 int[] max = new int [len2]; 8 max[0] =1; 9 for(int i=0;i<len;i++){ 10 for(int j=0;j<len2;j++){ 11 if(obstacleGrid[i][j]==1) 12 max[j]=0; 13 else if(j>0){ 14 max[j] = max[j]+max[j-1]; 15 } 16 } 17 } 18 return max[len2-1]; 19 } 20 }