Created
April 28, 2021 12:26
-
-
Save vrat28/8449d69a1aaaeebaac57de2d6f7a9f1a to your computer and use it in GitHub Desktop.
Unique Path with Obstacles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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