【LeetCode】63. Unique Paths II
Unique Paths II
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 1
and 0
respectively 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.
与上题差别不大,只需要判断有障碍置零即可。
对于首行首列,第一个障碍及之后的路径数均为0
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
if(obstacleGrid.empty())
return ;
int m = obstacleGrid.size();
if(obstacleGrid[].empty())
return ;
int n = obstacleGrid[].size();
vector<vector<int> > path(m, vector<int>(n, ));
for(int i = ; i < m; i ++)
{
if(obstacleGrid[i][] != )
path[i][] = ;
else
break;
}
for(int i = ; i < n; i ++)
{
if(obstacleGrid[][i] != )
path[][i] = ;
else
break;
}
for(int i = ; i < m; i ++)
{
for(int j = ; j < n; j ++)
{
if(obstacleGrid[i][j] == )
path[i][j] = ;
else
path[i][j] = path[i-][j] + path[i][j-];
}
}
return path[m-][n-];
}
};
【LeetCode】63. Unique Paths II的更多相关文章
- 【LeetCode】63. Unique Paths II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...
- 【一天一道LeetCode】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
- 【LeetCode】063. Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- LeetCode OJ 63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 【LeetCode】62. Unique Paths 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...
- [leetcode DP]63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 【LeetCode】62. Unique Paths
Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...
- 【LeetCode】062. Unique Paths
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- 【LeetCode】980. Unique Paths III解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...
随机推荐
- Git与SVN
http://www.nowamagic.net/academy/detail/48160207 前面提到,Linus一直痛恨CVS及SVN这些集中式的版本控制系统,为什么呢?Git是分布式版本控制系 ...
- img 边距的问题
一.*{margin:0;padding:0} 不能消除img的边距 二.布局中可以使用以下方法: 1.img:{flot:left} 2.img:{vertical-align: top;} im ...
- 关于orcad元件库
ORCAD CAPTURE 零件库解析 ORCAD CAPTURE 零件库解析 1' AMPLIFIER.OLB 共182个零件,存放模拟放大器IC,如CA3280,TL027C,EL4093等. 2 ...
- Shell升级,/bin/bash版本号4.1到4.3
bash环境变量存在随意代码运行漏洞:"通过CGI请求方式能够导致远程代码运行,进而导致server被入侵.危害严重.且官方发布补丁也被绕过", [漏洞影响]: 1)bash受影响 ...
- How to run WPF – XBAP as Full Trust Application
Recently I work on WPF-XBAP application that will run from intranet website: This application must h ...
- SpringMVC杂记(1) 使用阿里巴巴的fastjson
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- iOS Sqlite加密(FMDB/SQLCipher)
/** * 对数据库加密 * * @param path path description * * @return return value description */ + (BOOL)encryp ...
- OpenShift 如何获取bearer Token以便进行各种API调用
Openshift 需要通过bearer token的方式和API进行调用,比如基于Postman就可以了解到,输入bearer token后 1.如何获取Bearer Token 但Bearer T ...
- cocos2d-x v3.0各个环境下创建项目以及编译、执行官方DEMO
摘自:https://github.com/cocos2d/cocos2d-x/ 怎样创建一个新项目 How to start a new game Download the code from co ...
- JMeter压力测试和性能测试工具
Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测 试但后来扩展到其他测试领域. 它可以用于测试静态和动态资源例如静态文件 ...