leetcode63—Unique Path II
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
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.
Note: m and n will be at most 100.
Example 1:
Input: [ [0,0,0], [0,1,0], [0,0,0] ] Output: 2 Explanation: There is one obstacle in the middle of the 3x3 grid above. There are two ways to reach the bottom-right corner: 1. Right -> Right -> Down -> Down 2. Down -> Down -> Right –> Right
想法:与Unique Path类似,只不过需要考虑障碍物,将有障碍物出现的地方,result设置为0.如何m-1,n-1位置有障碍物,直接返回0
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int row = obstacleGrid.size();
].size();
int result[row][col];
; i < row ; i++){
; j < col ; j++){
){
result[i][j] = ;
}else{
&& j == ){
result[i][j] = ;
}else{
result[i][j] = ;
>= ){
result[i][j] += result[i-][j];
}
>= ){
result[i][j] += result[i][j-];
}
}
}
}
}
][col-];
}
};
leetcode63—Unique Path II的更多相关文章
- LeetCode 63. Unique Path II(所有不同路径之二)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- Unique path ii
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- leetcode-63. Unique Paths II · DP + vector
题面 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- LeetCode63 Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- Leetcode63.Unique Paths II不同路径2
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为"Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为" ...
- LeetCode之“动态规划”:Minimum Path Sum && Unique Paths && Unique Paths II
之所以将这三道题放在一起,是因为这三道题非常类似. 1. Minimum Path Sum 题目链接 题目要求: Given a m x n grid filled with non-negative ...
- [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )
Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corne ...
- 动态规划小结 - 二维动态规划 - 时间复杂度 O(n*n)的棋盘型,题 [LeetCode] Minimum Path Sum,Unique Paths II,Edit Distance
引言 二维动态规划中最常见的是棋盘型二维动态规划. 即 func(i, j) 往往只和 func(i-1, j-1), func(i-1, j) 以及 func(i, j-1) 有关 这种情况下,时间 ...
- 【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
随机推荐
- class文件打包成jar
电脑左下角“开始”——“运行”——输入cmd——cd+空格+clss文件所在文件夹的路径——jar+空格+-cf+空格+“jar包的名字”.jar+空格+*.class.好了...
- linux7 安装GitLab
1.安装Linux虚拟机-- 安装后配置a.停止防火墙# systemctl stop firewalld.service# systemctl disable firewalld.service# ...
- js飘窗
广告页上总会出现飘窗效果: adver_pos_id = getOtherParameter("id"); adver_Sid = getOtherParameter(" ...
- 第二十八天- tcp下的粘包和解决方案
1.什么是粘包 写在前面:只有TCP有粘包现象,UDP永远不会粘包 1.TCP下的粘包 因为TCP协议是面向连接.面向流的,收发两端(客户端和服务器端)都要有成对的socket,因此,发送端为了将多个 ...
- 各类无次数限制的免费API接口整理
各类无次数限制的免费API接口整理,主要是聚合数据上和API Store上的一些,还有一些其他的. 聚合数据提供30大类,160种以上基础数据API服务,国内最大的基础数据API服务,下面就罗列一些免 ...
- [转]SQL SERVER 2008 登陆失败(SQL和windows都没有对应的权限)
转自:http://www.cnblogs.com/zerocc/p/3425431.html 昨天在测试一些权限今天早上来就发现SQL SERVER 登陆不上去,报错为: 用户登陆失败:消息 184 ...
- Nginx的日志剖析
1.访问日志(access.log) Nginx的访问日志就是一个文件,它存储着每个用户对网站的访问请求,这个功能是有ngx_http_log_module模块来负责的,这个文件存在的主要目的就是为了 ...
- ubuntu更新下载源问题
Q1:ubuntu14.04系统安装完之后无法跟新并安装插件 cd /var/lib/apt/lists sudo rm * -rf sudo apt-get clean;sudo apt-get u ...
- 【jdk源码2】Objects源码学习
在学习上一个类TreeMap的时候,提到了这个类,这个类是jdk1.7新增的,里面有很多实用的方法.就是一个工具类,熟悉以后,如果里面有已经实现的方法,那么就不要再去实现了,省时省力省测试. 一.简单 ...
- Forbidden Attack:7万台web服务器陷入被攻击的险境
一些受VISA HTTPS保护的站点,因为存在漏洞容易受到Forbidden攻击,有将近70,000台服务器处于危险之中. 一种被称为"Forbidden攻击"的新攻击技术揭露许多 ...