leetcode 每日一题 63. 不同路径 II
Posted nil_f
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 每日一题 63. 不同路径 II相关的知识,希望对你有一定的参考价值。
动态规划
思路:
参考62. 不同路径
代码:
class Solution: def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int: m = len(obstacleGrid) n = len(obstacleGrid[0]) if obstacleGrid[0][0] == 1: return 0 obstacleGrid[0][0] = 1 for i in range(1,m): obstacleGrid[i][0] = int(obstacleGrid[i][0] == 0 and obstacleGrid[i-1][0] == 1) for j in range(1, n): obstacleGrid[0][j] = int(obstacleGrid[0][j] == 0 and obstacleGrid[0][j-1] == 1) for i in range(1,m): for j in range(1,n): if obstacleGrid[i][j] == 0: obstacleGrid[i][j] = obstacleGrid[i-1][j] + obstacleGrid[i][j-1] else: obstacleGrid[i][j] = 0 return obstacleGrid[m-1][n-1]
以上是关于leetcode 每日一题 63. 不同路径 II的主要内容,如果未能解决你的问题,请参考以下文章