static int x=[](){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}();
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int row = obstacleGrid.size();
int col = obstacleGrid[0].size();
vector<vector<int>> mat(row, vector<int>(col, 0));
for (int i = 0; i < col; i++){
if (obstacleGrid[0][i] == 1)
break;
mat[0][i] = 1;
}
for (int i = 0; i < row; i++){
if (obstacleGrid[i][0] == 1)
break;
mat[i][0] = 1;
}
for (int i = 1; i < row; i++)
for (int j = 1; j < col; j++)
if (obstacleGrid[i][j] != 1)
mat[i][j] = mat[i - 1][j] + mat[i][j - 1];
return mat[row - 1][col - 1];
}
};
LetCode 63. 不同路径 II
最新推荐文章于 2022-04-06 20:50:29 发布