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.

与上题差别不大,只需要判断有障碍置零即可。

对于首行首列,第一个障碍及之后的路径数均为0

class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
if(obstacleGrid.empty())
return ;
int m = obstacleGrid.size();
if(obstacleGrid[].empty())
return ;
int n = obstacleGrid[].size();
vector<vector<int> > path(m, vector<int>(n, ));
for(int i = ; i < m; i ++)
{
if(obstacleGrid[i][] != )
path[i][] = ;
else
break;
}
for(int i = ; i < n; i ++)
{
if(obstacleGrid[][i] != )
path[][i] = ;
else
break;
}
for(int i = ; i < m; i ++)
{
for(int j = ; j < n; j ++)
{
if(obstacleGrid[i][j] == )
path[i][j] = ;
else
path[i][j] = path[i-][j] + path[i][j-];
}
}
return path[m-][n-];
}
};

【LeetCode】63. Unique Paths II的更多相关文章

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

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

  2. 【一天一道LeetCode】#63. Unique Paths II

    一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...

  3. 【LeetCode】063. Unique Paths II

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

  4. LeetCode OJ 63. Unique Paths II

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

  5. 【LeetCode】62. Unique Paths 解题报告(Python & C++)

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

  6. [leetcode DP]63. Unique Paths II

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

  7. 【LeetCode】62. Unique Paths

    Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...

  8. 【LeetCode】062. Unique Paths

    题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

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

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

随机推荐

  1. ReactNative 调用手机地图(高德、百度)导航 Android

    由于项目需要,鉴于第三方sdk包的体积略大,经过评估论证后,决定采用调起APP以及网页地图的方式来进行导航. 思路: 在需要调用导航的界面通过原生获取当前手机内可用的导航app组装成列表返回到RN待选 ...

  2. ruby 状态转移

    0. 引言       昨天遇到一个问题,就是关于对象状态转移的问题,我姑且这样命名吧.简要描述一下就是:对于一个人,他有进食,帮助他人,恋爱等功能,但是这些功能是有先后顺序的,对于刚出生的人,他要先 ...

  3. Apache commons——Apache旗下的通用工具包项目

    Apache Commons是Apache旗下的一个开源项目,包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动 这里是Apache commons的官方网站 下面是工具的简单介绍: ...

  4. RTL8188EUS带天线的WiFi模块

    http://www.liuliutech.com/ProductShow.asp?ID=121 一,公司介绍瑞昱(REALTEK)半导体成立于1987年,位于台湾[硅谷]的新竹科学园区.凭借着7位创 ...

  5. Socket INADDR_ANY详解

    转载:http://hi.baidu.com/zorro_knight/item/37af9e8c9dc71253e73d1924 linux下的socket INADDR_ANY表示的是一个服务器上 ...

  6. 第十四章 openwrt 安装 python

    需要安装libffi,python-mini,python.libffi以及python-mini需要安装在python之前     如果部分软件包不一样可以在下面的web后台搜索,搜索前先opkg ...

  7. [Linux] du-查看文件夹大小-并按大小进行排序

    reference : http://blog.csdn.net/jiaobuchong/article/details/50272761# 某天,我想检查一下电脑硬盘的的使用情况,作为一个命令控,废 ...

  8. 推荐两份学习 Kotlin 和机器学习的资料

    最近 Kotlin 和人工智能比较火,有不少同学留言问我怎么学习 Kotlin,怎么学习机器学习,今天就给大家推荐两份不错的学习资料. 1. Kotlin 学习资料其实,在我看来最好的学习资料就是 K ...

  9. DICOMDIR

    DICOMDIR 是一个可变长度 迷你 database 文件.由 group (0002, xxxx) 和 group (0004, xxxx) 为主题.描述的是一个 4 层的树状结构 (tree ...

  10. Centos7 启动 python脚本

    假设文件夹\home\sks\python3_crawl下面有个test.py 文件 打开terminal终端:转到root模式 进入cd /hom/sks/python3_crawl 执行:pyth ...