-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec10_22.cpp
More file actions
24 lines (21 loc) · 732 Bytes
/
Copy pathlec10_22.cpp
File metadata and controls
24 lines (21 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>>& mat) {
int n =mat.size();
int m = mat[0].size();
int dp[n][m];
for(int i = 0 ; i<n;i++){
for(int j = 0 ; j<m; j++){
if(mat[i][j] == 1 ) dp[i][j] = 0 ;
else if( i == 0 && j == 0 ) dp[i][j] = 1;
else{
int up = 0 , left = 0;
if(i>0) up = dp[i-1][j];
if(j>0) left = dp[i][j-1];
dp[i][j] = (up + left);
}
}
}
return dp[n-1][m-1];
}
};