35 lines
894 B
Java
35 lines
894 B
Java
/*
|
|
* @lc app=leetcode id=63 lang=java
|
|
*
|
|
* [63] Unique Paths II
|
|
*/
|
|
|
|
// @lc code=start
|
|
class Solution {
|
|
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
|
|
int[][] dp = new int[obstacleGrid.length][obstacleGrid[0].length];
|
|
for(int i=0;i<dp.length;i++) {
|
|
for(int j=0;j<dp[0].length;j++) {
|
|
dp[i][j] = 0;
|
|
}
|
|
}
|
|
dp[0][0] = obstacleGrid[0][0]==1?0:1;
|
|
for(int i = 0; i<dp.length; i++) {
|
|
for(int j=0; j<dp[0].length; j++) {
|
|
if(obstacleGrid[i][j] == 1) {
|
|
continue;
|
|
}
|
|
if(i-1>=0) {
|
|
dp[i][j] += dp[i-1][j];
|
|
}
|
|
if(j-1>=0) {
|
|
dp[i][j] += dp[i][j-1];
|
|
}
|
|
}
|
|
}
|
|
return dp[dp.length-1][dp[0].length-1];
|
|
}
|
|
}
|
|
// @lc code=end
|
|
|