Unique Paths II

Total Accepted: 31019 Total Submissions: 110866My Submissions

Question Solution 

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 解题报告的更多相关文章

  1. 【LeetCode】63. Unique Paths II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...

  2. 【LeetCode】Permutations II 解题报告

    [题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...

  3. LEETCODE —— Unique Paths II [动态规划 Dynamic Programming]

    唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...

  4. LEETCODE —— Unique Paths II [Dynamic Programming]

    唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...

  5. [leetcode]Unique Paths II @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths-ii/ 题意: Follow up for "Unique Paths": N ...

  6. [LeetCode] Unique Paths II 不同的路径之二

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  7. Leetcode Unique Paths II

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  8. [Leetcode] unique paths ii 独特路径

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  9. 【LeetCode】980. Unique Paths III解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

随机推荐

  1. 3.3 SQLite数据库

    1.使用嵌入式关系型SQLite数据库存储数据 轻量级嵌入式数据库引擎,它支持 SQL 语言,并且只利用很少的内存就有很好的性能.SQLite最大的特点是你可以把各种类型的数据保存到任何字段中,而不用 ...

  2. delphi平方开方

    用delphi自带的sqr和sqrt函数 procedure TForm2.SpeedButton3Click(Sender: TObject); begin ShowMessage(Sqr(6).T ...

  3. 关闭Ubuntu 12.04的内部错误提示

    刚装完系统后,才安装一个输入法重启电脑后,竟然就提示'内部错误'需要提交报告,什么状况? 发扬'不求甚解'的光荣传统,我又不搞Linux开发,对我来说只是个工具而已,工具出问题了解决问题即可不想劳神深 ...

  4. Winform(C#.NET)自动更新组件的使用及部分功能实现(续)

    接昨天的文章Winform(C#.NET)自动更新组件的使用及部分功能实现 强制更新的实现部分: 将DownloadConfirm窗体修改成单纯的类 public class DownloadConf ...

  5. .NET Socket TCP 50W在线连接交互测试

    在平常的交流中经常有人问.net socket能支持多少在线?和C++或linux下比起来应该差很远吧?其实产生这样问题的主要原因是.net很少人去做这方面的测试,而在linux下则经常听到什么100 ...

  6. 2014年市场需求排名前10的编程语言 - 生命的延续是 BI

    开篇介绍 2014年就快收尾了,Team 内部每人都会准备一些 Tech Talk 的内容,技术方面的,咨询方面的都可以.我就准备了一些有关 BI 排名,BI 报表排名,包括各种技术编程语言等相关排名 ...

  7. [WinAPI] 串口1-创建[包括: 打不开串口]

    本来是用一个USB扩展把一个USB括成4个,然后把USB转串口连接上,虽然设备管理器可以找到用SSCOM也能找到,但是用API就是打不开,最后把USB转串插在电脑的一个USB上就可以啦! #inclu ...

  8. 无线客户端框架设计(5):调用MobileAPI的设计(iOS篇)

    这一节讲如何发起网络请求. iOS用于调用MobileAPI的第三方组件很多,我们这里采用的是以下组件: 1)ASIHTTPRequest,用于请求MobileAPI:http://allseeing ...

  9. java web开发 图片上传功能

    基本思路在于,配置路径,然后用java I/O的api将图片上传到该目录下. String photoPath =    ServletActionContext.getServletContext( ...

  10. sql 取首次投资的人

    --- 11月 ---首次投资笔数和投资金额 ) AS stNum,sum(amount) AS stAmount FROM ( ),createtime,) AS riqi,a.amount,a.u ...