-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunique-paths-ii.cpp
39 lines (36 loc) · 1004 Bytes
/
unique-paths-ii.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "header.h"
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
int dp[105][105];
int m = obstacleGrid.size();
if(m==0) {
return 0;
}
int n = obstacleGrid[0].size();
for(int i = 1; i <= m; i++) {
for(int j = 1; j <= n; j++) {
if(obstacleGrid[i-1][j-1] == 1) {
dp[i][j] = 0;
}
else {
if( i == 1 && j == 1) {
dp[i][j] = 1;
}
else if(i == 1) {
dp[i][j] = dp[i][j-1];
}
else if(j == 1) {
dp[i][j] = dp[i-1][j];
}
else {
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
}
}
return dp[m][n];
}
};
int main() {
}