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 ...
随机推荐
- 大菲波数(Fibonacci)java大数(hdu1715)
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...
- 几个常用T_SQL语句比较
UNION ALL VS UNION : union all 对两个结果进行并集操作,包括重复行,即所有的结果全部显示,不管是不是重复:union 对两个结果集进行并集操作,不包括重复行,相当于 di ...
- SSM整合的pom.xml依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 微信小程序获取当前地址以及选择地址详解 地点标记
首先定义事件: bindtap='getLocation' <view class='store-bot' bindtap='getLocation'> <view class='c ...
- JS代理模式实现图片预加载
---恢复内容开始--- 刚刚说了懒加载,现在我们来搞搞预加载吧 预加载的核心: 图片等静态资源在使用前提前请求. 资源后续使用可以直接从缓存中加载,提升用户体验. 几个误区: 预加载不是为了减少页面 ...
- 关于Mysql数据库的知识总结
2017年6月8日,天气阴.心情晴. 连续做梦两个晚上了,昨晚竟然梦见一个很长时间不联系的初中同学了,早上上班的路上聊了聊.女孩现在出差在贵州,风景秀美的地方.我说“你现在生活很滋润”.女孩说“那是你 ...
- <Android 基础(三十三)> TabHost ~ 仿微信底部菜单
简介 Container for a tabbed window view. This object holds two children: a set of tab labels that the ...
- servlet3.0 web.xml 标头
<?xml version="1.1" encoding="UTF-8"?> <web-app xmlns="http://java ...
- JAVA EE期末项目-校园小商店
校园小商店 一.项目成员及分工 我(计科二班袁文雪)和队友(计科二班蒋媛)设计了一款面对校园的网上购物商店. 我的工作:理解分析代码,编写文档. 二.项目需求分析 网上商店系统主要是实现学生网上选商品 ...
- Android Studio之could not reserve enough space for object heap报错
在用AndroidStudio时出现这样的错误: 搞了半天终于找到了解决办法,但是很麻烦.就是每次创建工程后,在gradle.properties文件中加入如下代码: org.gradle.jvma ...