Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created April 28, 2021 12:28
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/009d5c11103b0dda5d6c390bf2624cb1 to your computer and use it in GitHub Desktop.
Save vrat28/009d5c11103b0dda5d6c390bf2624cb1 to your computer and use it in GitHub Desktop.
Unique Path ii
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