Advertisement
nikunjsoni

63

Jun 14th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int uniquePathsWithObstacles(vector<vector<int>>& g) {
  4.         int rows = g.size(), cols = g[0].size();
  5.         int dp[rows+1][cols+1];
  6.         memset(dp, 0, sizeof dp);
  7.         if(!g[0][0])
  8.             dp[1][1] = 1;
  9.         for(int i=1; i<=rows; i++){
  10.             for(int j=1; j<=cols; j++){
  11.                 if(g[i-1][j-1] == 1) continue;
  12.                 dp[i][j] += dp[i-1][j];
  13.                 dp[i][j] += dp[i][j-1];
  14.             }
  15.         }
  16.         return dp[rows][cols];
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement