水题,和上一题一样的。
class Solution {
public:
long long int dp[105][105];
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
for(int i=0;i<obstacleGrid.size();i++)
{
for(int j=0;j<obstacleGrid[0].size();j++)
{
if(obstacleGrid[i][j]==1)
{
dp[i][j]=0;
continue;
}
if(i==0&&j==0)
{
dp[i][j]=1;
continue;
}
if(i==0)
{
dp[i][j] = dp[i][j-1];
continue;
}
if(j==0)
{
dp[i][j] = dp[i-1][j];
continue;
}
dp[i][j]=dp[i][j-1]+dp[i-1][j];
}
}
return dp[obstacleGrid.size()-1][obstacleGrid[0].size()-1];
}
};