Created
April 28, 2021 12:28
-
-
Save vrat28/009d5c11103b0dda5d6c390bf2624cb1 to your computer and use it in GitHub Desktop.
Unique Path ii
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: | |
def uniquePathsWithObstacles(self, OG: List[List[int]]) -> int: | |
if OG[0][0]: return 0 | |
m, n = len(OG), len(OG[0]) | |
dp = [[0] * n for _ in range(m)] | |
dp[0][0] = 1 | |
for i in range(m): | |
for j in range(n): | |
if OG[i][j] or (i == 0 and j == 0): continue | |
dp[i][j] = (dp[i-1][j] if i else 0) + (dp[i][j-1] if j else 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