LeetCode: 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.
SOULUTION 1:
跟LeetCode: Unique Paths 解题报告 相比,只不过是判断一下当前是不是block,如果是block,直接设置D[i][j] 是0就好了 也就是不可达。 同样在3分钟之内Bug free 秒答,哦耶!
public class Solution {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
//
if (obstacleGrid == null || obstacleGrid.length == || obstacleGrid[].length == ) {
return ;
} int rows = obstacleGrid.length;
int cols = obstacleGrid[].length; int[][] D = new int[rows][cols]; for (int i = ; i < rows; i++) {
for (int j = ; j < cols; j++) {
D[i][j] = ;
if (obstacleGrid[i][j] == ) {
D[i][j] = ;
} else {
if (i == && j == ) {
D[i][j] = ;
} if (i != ) {
D[i][j] += D[i - ][j];
} if (j != ) {
D[i][j] += D[i][j - ];
}
}
}
} return D[rows - ][cols - ];
}
}
LeetCode: Unique Paths II 解题报告的更多相关文章
- 【LeetCode】63. Unique Paths II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...
- 【LeetCode】Permutations II 解题报告
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...
- LEETCODE —— Unique Paths II [动态规划 Dynamic Programming]
唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...
- LEETCODE —— Unique Paths II [Dynamic Programming]
唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...
- [leetcode]Unique Paths II @ Python
原题地址:https://oj.leetcode.com/problems/unique-paths-ii/ 题意: Follow up for "Unique Paths": N ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- Leetcode Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [Leetcode] unique paths ii 独特路径
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 【LeetCode】980. Unique Paths III解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...
随机推荐
- 黑马程序员——for循环的使用与理解
Console.WriteLine("请输入要打印菱形的行数(不能是偶数)");---------------------- <a href="http://edu ...
- Orchard Compact v1.7.2
1. 仅包留了Core中的Settings和Shapes, 及Modules, Themes和jQuery模块. 2. 添加了对Oracle的支持. 下载地址: 二进制: Orchard.Compac ...
- IHttpActionResult – new way of creating responses in ASP.NET Web API 2
先收藏这篇文章. http://www.strathweb.com/2013/06/ihttpactionresult-new-way-of-creating-responses-in-asp-net ...
- 个性二维码开源专题<前背景>
//设置图片资源 private Image imgAgo; public override void SetParam() { base.SetParam(); // 读取前背景 string _i ...
- Lambda表达式的前世今生
Lambda 表达式 早在 C# 1.0 时,C#中就引入了委托(delegate)类型的概念.通过使用这个类型,我们可以将函数作为参数进行传递.在某种意义上,委托可理解为一种托管的强类型的函数指针. ...
- ActiveMQ第四弹:在HermesJMS中创建ActiveMQ Session
Hermes JMS是一个开源免费的跨平台的JMS消息监听工具.它可以很方便和各种JMS框架集成和交互,可以用来监听.发送.接收.修改.存储消息等.这篇文章将讲解HermesJMS如何集成Active ...
- 北大青鸟进入ASP.NET MVC的世界(一)
今天我们开始ASP.NET MVC 4.0课程的学习第一讲.我们今天主要关注如下5个问题: 1.理解ASP.NET MVC程序的执行过程 2.会使用ASP.NET中的系统对象 3.会搭建ASP.NE ...
- 在DOS下的DEBUG命令的详细用法
在DOS下的DEBUG命令的详细用法 名称 解释 格式 a (Assemble) 逐行汇编 a [address] c (Compare) 比较两内存块 c range address d (Dump ...
- Redis教程(六):Sorted-Sets数据类型
转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/133.html 一.概述: Sorted-Sets和Sets类型极为相似, ...
- asp.net webAPI 自动生成帮助文档并测试
之前在项目中有用到webapi对外提供接口,发现在项目中有根据webapi的方法和注释自动生成帮助文档,还可以测试webapi方法,功能很是强大,现拿出来与大家分享一下. 先看一下生成的webapi文 ...