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. 4.27-4.30webstorm

    本周学习了html的基础课程,运用的软件是webstorm,网页的结构大体为: <html><head> My First Heading </head> < ...

  2. Hyper-V初涉_早期Windows安装虚拟硬件驱动

    虽然微软已经一再强调将要对Windows XP停止提供服务,但是难免在一些特殊场合需要早期的系统进行测试.为了测试需要,我在Hyper-V中安装了Windows XP. 按照之前的方法,对Hyper- ...

  3. codeforces 425C

    题意:给定长度为n,m<=100000的范围在100000以内的数组a,b. 现在给定两种操作: 第一种是ai,bj相等,ai,bj之前的数全删掉,费用为e,收益为1 第二种是把剩下的全部删掉, ...

  4. Java和C#中的接口对比(有你不知道的东西)

    1.与Java不同,C#中的接口不能包含字段(Field). 在java中,接口中可以包含字段,但是这些字段隐式地是static和final的.而C#不允许接口中有字段,编译器在编译时就会提示错误(如 ...

  5. 一个Java应用,三种字体风格(Java, Windows, Mac),真是蛋疼

    大家看看下面这张图,红色圈起来的是Java难看至极的字体渲染,黄色圈起来的是正常的Windows渲染,绿色是Mac风格的渲染. 其实我感觉正常风格就挺好的,就是看那个Java的Swing菜单,非常不顺 ...

  6. jQuery演示10种不同的切换图片列表动画效果以及tab动画演示 2

    很常用的一款特效纯CSS完成tab实现5种不同切换对应内容效果 实例预览 下载地址 实例代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...

  7. Shell脚本学习入门(一)

    1.Shell脚本是解释型的语言. 2.Shell脚本建立的基本步骤: 3.Shell脚本文件的第一行一般可以是:"#! 路径名 -(选项)", 为了要使Shell脚本有移植性,请 ...

  8. ThinkPHP中关于JS文件如何添加类似__PUBLIC__图片路径

    在对html样式进行优化的时候,经常会用到Js/jquery进行一些跳转切换的样式,而我们常做的就是在Js/jquery代码中嵌url图片链接代码,以实现动态交互的页面效果. 如下图所示:

  9. JQ中 trigger()和triggerHandler()区别

    既然使用了trigger和triggerHandler,那么你应该了解了他们的差别了. trigger():在每一个匹配的元素上触发某类事件. triggerHandler():这个特别的方法将会触发 ...

  10. [推荐]DataX、DbSync和Timetunnel学习贴

    [推荐]DataX.DbSync和Timetunnel学习贴 一 DataX 二 DbSync 三  Timetunnel TimeTunnel :http://code.taobao.org/p/T ...