【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 ...
随机推荐
- HDU 3974 Assign the task 并查集/图论/线段树
Assign the task Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- 查看linux并发连接数的方法
查看Web服务器(Nginx Apache)的并发请求数及其TCP连接状态:netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, ...
- JAVA RMI调用实战学习
JAVA RMI 实战示例,参考网址: http://diaoge.iteye.com/blog/245170 这个示例很清楚地阐释了rmi的使用方法, 但示例都是放在一起的, 实际使用中我们可能会将 ...
- mysql重启,重启释放ibtmp1
1.通过rpm包安装的MySQL service mysqld restart 2.从源码包安装的MySQL // linux关闭MySQL的命令$mysql_dir/bin/mysqladmin - ...
- 一个Loading 遮罩效果
1.需要两个DIV,一个用来遮罩,另一个用来显示Loading图片和文字(初始时它们是隐藏的) .gdiv_over { display: none; position: absolute; top: ...
- SVG 可伸缩矢量图形 简介 Path路径
w3school:http://www.w3school.com.cn/svg/svg_intro.asp SVG 意为可缩放矢量图形(Scalable Vector Graphics). SVG ...
- C++实现委托机制(一)
1.引言: 如果你接触过C#,你就会觉得C#中的delegate(委托)十分灵巧,它的用法上和C\C++的函数指针很像,但是却又比C\C++的函数指针更加灵活.并且委托可以一对多,也就是可以注册多个函 ...
- by,with
一.表示使用有形的工具时,通常用with来表示.例如: 用钢笔写 write with a pen 用肉眼看 see with naked eyes 用锤子敲打 strike with a hamme ...
- java学习笔记15--多线程编程基础2
本文地址:http://www.cnblogs.com/archimedes/p/java-study-note15.html,转载请注明源地址. 线程的生命周期 1.线程的生命周期 线程从产生到消亡 ...
- Java 中 方法名或类名 变更 同时 更新 所有引用的 类名或方法名 的解决方案
选中 类名,或属性名 Ctrl + 1 然后选择 理新当前文件,还是更新整个工作空间,然后修改对应的类名或方法名 回车即可. 如果.有SVN 版本在控制着,则 会提示,然后把对应的文件 锁定 再 ...