leetCode63. 不同路径 II
题目思路
代码
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>>& ob) {
int n = ob.size();
if(!n) return 0;
int m = ob[0].size();
vector<vector<int>> f(n,vector<int>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(!ob[i][j]){
if(!i && !j) f[i][j] = 1;
else{
if(i) f[i][j] += f[i - 1][j];
if(j) f[i][j] += f[i][j - 1];
}
}
}
}
return f[n - 1][m - 1];
}
};