

public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
int rowLen = obstacleGrid.length;
int rankLen = obstacleGrid[0].length;;
int [][] dp = new int [rowLen][rankLen];
dp[0][0] = obstacleGrid[0][0] == 0 ? 1 : 0;
if(dp[0][0] == 0){
return 0 ;
}
for(int j = 1;j < rankLen;j++){
if(obstacleGrid[0][j] != 1){
dp[0][j] = dp[0][j-1];
}
}
for(int r = 1;r < rowLen;r++){
if(obstacleGrid[r][0] != 1){
dp[r][0] = dp[r-1][0];
}
}
for(int i = 1;i < rowLen;i++){
for(int r = 1;r < rankLen;r++){
if(obstacleGrid[i][r] != 1){
dp[i][r] = dp[i-1][r] +dp[i][r-1];
}
}
}
return dp[rowLen-1][rankLen-1];
}
public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
int rowLen = obstacleGrid.length;
int rankLen = obstacleGrid[0].length;;
int [] result = new int[rankLen];
Arrays.fill(result,0);
for(int i = 0;i < rowLen;i++){
for(int j = 0;j < rankLen;j++){
if(i == 0 && j == 0){
result[j] = 1;
}
if(obstacleGrid[i][j] == 1){
result[j] = 0;
}else if(j > 0){
result[j] += result[j-1];
}
}
}
return result[rankLen-1];