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