Leetcode 63 Unique Paths II
2016-04-27 18:17
204 查看
Follow up for "Unique Paths":
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as
For example,
There is one obstacle in the middle of a 3x3 grid as illustrated below.
The total number of unique paths is
Note: m and n will be at most 100.
先把两条边初始化了然后dp
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as
1and
0respectively in the grid.
For example,
There is one obstacle in the middle of a 3x3 grid as illustrated below.
[ [0,0,0], [0,1,0], [0,0,0] ]
The total number of unique paths is
2.
Note: m and n will be at most 100.
先把两条边初始化了然后dp
class Solution(object): def uniquePathsWithObstacles(self, ob): m, n = len(ob), len(ob[0]) dp = [[0 for i in range(n)] for j in range(m)] for i in range(m): if ob[i][0]: break dp[i][0] = 1 for j in range(n): if ob[0][j]: break dp[0][j] = 1 for i in range(1,m): for j in range(1,n): if ob[i][j]: continue dp[i][j] = dp[i-1][j] + dp[i][j-1] return dp[-1][-1]
相关文章推荐
- mui待解决问题
- Guice:轻量级IOC/DI 容器
- 四种方法实现UITableView的cell高度自动计算
- UINavigationController下view及子view的坐标及高度
- Android相关属性的介绍:android:exported = true
- ios集成环信 easeUI SDK 3.0 SDK 2.0 出错遇到的所有问题
- Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Must specify unique android
- SSH RSA host key for has changed and you have requeste
- 自定义UITabbarItem的title字体颜色
- Android Studio在build的时候出现transformClassesWithDexForDebug
- 303. Range Sum Query - Immutable
- Arduino ESP8266编程深入要点
- Arduino ESP8266编程深入要点
- android studio 启动项目时“Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled”
- Java 7 关于break和continue后的标签
- 5.0systemUI启动流程
- UItabBar上添加红点
- iOS开发--UIImage转化成NSData
- boundingRectWithSize 的使用, 计算UILable高度, 包含Emoji及多属性string.
- git Pull Request 是什么意思?