63. 不同路径 II

class Solution:
    def uniquePathsWithObstacles(self, obstacleGrid):
        """
        :type obstacleGrid: List[List[int]]
        :rtype: int
        """
        n,m = len(obstacleGrid),len(obstacleGrid[0])
        dp = [[0]*m for _ in range(n)]
        dp[0][0] = 1 if obstacleGrid[0][0] == 0 else 0
        for i in range(n):
            for j in range(m):
                if obstacleGrid[i][j] == 0:
                    if i+1<n:
                        dp[i+1][j] += dp[i][j]
                    if j+1<m:
                        dp[i][j+1] += dp[i][j]
                else:
                    dp[i][j] = 0
        return dp[n-1][m-1]

相关文章:

  • 2022-02-18
  • 2022-12-23
  • 2021-11-09
  • 2021-09-03
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2022-01-07
  • 2021-09-27
  • 2021-08-04
  • 2021-12-07
相关资源
相似解决方案