首页 > 其他 > 详细

leetcode63

时间:2019-12-10 23:19:04      阅读:84      评论:0      收藏:0      [点我收藏+]
 1 class Solution:
 2     def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
 3         m = len(obstacleGrid)
 4         n = len(obstacleGrid[0])
 5         dp = [[0 for _ in range(n)]for _ in range(m)]
 6         for j in range(n):
 7             if obstacleGrid[0][j] == 0:
 8                 dp[0][j] = 1
 9             else:
10                 break
11         for i in range(m):
12             if obstacleGrid[i][0] == 0:
13                 dp[i][0] = 1
14             else:
15                 break
16         for i in range(1,m):
17             for j in range(1,n):
18                 if obstacleGrid[i][j] == 0:
19                     dp[i][j] = dp[i-1][j] + dp[i][j-1]
20                 else:
21                     dp[i][j] = 0
22         return dp[m-1][n-1]

leetcode62的基础上,增加对障碍物的判断。

leetcode63

原文:https://www.cnblogs.com/asenyang/p/12019634.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!