不同的路径 II

时间:2022-09-07 15:44:41
class Solution {
public:
/**
* @param obstacleGrid: A list of lists of integers
* @return: An integer
*/
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
// write your code here
int m = obstacleGrid.size();
if(m==) return ;
int n = obstacleGrid[].size();
int a[m][n];
int temp=;
for(int i=;i<m;++i){
a[i][]=;
if(obstacleGrid[i][]==){
temp = i;
a[i][]=;
}
if(i>=temp)
a[i][]=;
}
temp = ;
for(int j=;j<n;++j){
a[][j]=;
if(obstacleGrid[][j]==){
temp = j;
a[][j]=;
}
if(j>=temp)
a[][j]=;
}
for(int i =;i < m;++i){
for(int j =;j<n;++j){
a[i][j]=a[i-][j]+a[i][j-];
if(obstacleGrid[i][j]==)
a[i][j]=;
}
}
return a[m-][n-];
}
};