# leetcode 62. Unique Paths（动态规划）

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below).
How many possible unique paths are there?

//leetcode 62. Unique Paths
public int uniquePaths(int m, int n) {
int[][] memo = new int[n][m];
for(int i=0;i<n;i++)
memo[i][0] = 1;
for(int i=0;i<m;i++)
memo[0][i] = 1;
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
memo[i][j] = memo[i-1][j] + memo[i][j-1];
}
}
return memo[n-1][m-1];

}


leetcode 63. Unique Paths II

//leetcode 63. Unique Paths II
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
int n = obstacleGrid.length;
if(n==0)
return 0;
int m = obstacleGrid[0].length;
int[][] memo = new int[n][m];
if(obstacleGrid[0][0] == 0)
memo[0][0] = 1;
else
memo[0][0] = 0;
for(int i=1;i<n;i++){
if(obstacleGrid[i][0] == 0)
memo[i][0] = memo[i-1][0];
else
memo[i][0] = 0;
}
for(int i=1;i<m;i++){
if(obstacleGrid[0][i] == 0)
memo[0][i] = memo[0][i-1];
else
memo[0][i] = 0;
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
if(obstacleGrid[i][j] == 0)
memo[i][j] = memo[i-1][j] + memo[i][j-1];
else
memo[i][j] = 0;

}
}
return  memo[n-1][m-1];

}