题目链接:
LeetCode 63 — Unique Paths II
AC代码:
public class Problem63 {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
int m=obstacleGrid.length;
int n =obstacleGrid[0].length;
int[][] a=new int[m][n];
a[0][0]=1;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(obstacleGrid[i][j]==1) {
a[i][j]=0;
continue;
}
int k1=0,k2=0;
if(i!=0) k1=a[i-1][j];
if(j!=0) k2=a[i][j-1];
if(k1+k2!=0) a[i][j]=k1+k2;
}
}
return a[m-1][n-1];
}
}