Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created April 28, 2021 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/8449d69a1aaaeebaac57de2d6f7a9f1a to your computer and use it in GitHub Desktop.
Save vrat28/8449d69a1aaaeebaac57de2d6f7a9f1a to your computer and use it in GitHub Desktop.
Unique Path with Obstacles
class Solution {
public int uniquePathsWithObstacles(int[][] OG) {
if (OG[0][0] == 1) return 0;
int m = OG.length, n = OG[0].length;
int[][] dp = new int[m][n];
dp[0][0] = 1;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
if (OG[i][j] == 1 || (i == 0 && j == 0)) continue;
else dp[i][j] = (i > 0 ? dp[i-1][j] : 0) + (j > 0 ? dp[i][j-1] : 0);
return dp[m-1][n-1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment