corner
below
diagram
obstacles
java
class Solution {
public int uniquePathsWithObstacles(int[][] g) {
int x = g.length ;
int y = g[0].length;
int arr[][] = new int [x][y];
for(int i = 0 ; i < x ; i++){
for(int j = 0 ; j < y ; j++){
if(g[i][j]!=0) continue;
if(i==0&&j==0)arr[i][j] =1 ;
if(j> 0 )arr[i][j] += arr[i][j-1];
if(i> 0 )arr[i][j] += arr[i-1][j];
}
}
return arr[x-1][y-1];
}
}python

京公网安备 11010502036488号