链接:https://leetcode-cn.com/problems/unique-paths-ii/submissions/
与上一题类似,注意有障碍物的地方方法数直接置为0.
class Solution {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
int temp [] = new int [obstacleGrid[0].length];
for(int i = 0;i<obstacleGrid.length;i++)
{
for(int j = 0;j<obstacleGrid[0].length;j++)
{
if(obstacleGrid[i][j] == 1)
temp[j] = 0;
else if(i==0&&j==0)
temp[j] = 1;
else if(i==0)
temp[j] =temp[j-1];
else if(j!=0)
temp[j] = temp[j]+temp[j-1];
}
}
return temp[obstacleGrid[0].length-1];
}
}