LeetCode题解之Unique Paths II
1、题目描述

2、问题描述
使用动态规划算法,加上条件检测即可
3、代码
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int m = obstacleGrid.size() ;
int n = obstacleGrid[].size() ;
vector<vector<int>> sum(m , vector<int>(n, ));
bool isOb = false;
for( int i = ; i < m; i++){
if( obstacleGrid[i][] == ) isOb = true;
if( isOb ){
sum[i][] = ;
}
else{
sum[i][] = ;
}
}
isOb = false;
for(int j = ; j < n; j++){
if( obstacleGrid[][j] == ) isOb = true;
if( isOb ){
sum[][j] = ;
}
else{
sum[][j] = ;
}
}
for(int i = ; i < m; i++){
for( int j = ; j < n; j++){
if( obstacleGrid[i][j] == )
sum[i][j] == ;
else
sum[i][j] = sum[i-][j] + sum[i][j-];
}
}
return sum[m-][n-];
}
LeetCode题解之Unique Paths II的更多相关文章
- 【LeetCode练习题】Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- 【一天一道LeetCode】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
- 【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- 【LeetCode】063. Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- 【LeetCode】63. Unique Paths II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...
- LeetCode OJ 63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [leetcode DP]63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- LeetCode OJ:Unique Paths II(唯一路径II)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- leetcode@ [62/63] Unique Paths II
class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleG ...
随机推荐
- node.js的
node.js入门 http://www.cnblogs.com/rubylouvre/archive/2010/07/15/1778403.html 专题:Node.js专区http://devel ...
- 解决tomcat使用时catalina.out过大的问题
在项目上线之前需要做很多事情,其中最容易忘记的就是禁用不必要的日志和调整必要的参数. 调整参数这里主要指的是最大连接数,最小等待时间,虚拟机内存等. 而这里重点要提出的是,你需要禁用tomcat中不必 ...
- java操作特殊字符需要注意的点
在使用字符串替换,分离时 我们如果想替换一个字符串中的问号,我们就不能直接写问号,而要写[?] 实例如下 str = str.replaceAll("\""," ...
- Go的方法集
方法集定义了接口的接受规则. package main import "fmt" type notifier interface { notify() } type user st ...
- 2015年第六届蓝桥杯C/C++程序设计本科B组决赛 完美正方形
完美正方形 如果一些边长互不相同的正方形,可以恰好拼出一个更大的正方形,则称其为完美正方形.历史上,人们花了很久才找到了若干完美正方形.比如:如下边长的22个正方形 2 3 4 6 7 8 12 13 ...
- Spring Import注解
今天了解了,Spring @Import的使用 先贴上Spring官方关于Spring @Import注解的文档链接 https://docs.spring.io/spring/docs/3.0. ...
- 浅谈.net jenkins svn下自动化集成环境安装 搭建 配置
本人做.net研发已有3年多了,之前一直偏向于技术研究,自己学了很多技术,现在突然发现学了那么多技术有什么用呢?真正用到的并不多. 现在?算是一只小鸟吧,自嘲下.....毕竟我是90后,很多领导对于9 ...
- Dev-FAT-UAT-PRO
DEV Development environment FAT Feature Acceptance Test environment UAT User Acceptance Test environ ...
- MVC添加数据并存入数据库
你可以下载演示的数据库,在这篇<MVC显示详细记录Without Entity Framework>http://www.cnblogs.com/insus/p/3366608.html结 ...
- EPPlus批量插入图片到Excel
#region 测试EPPlus插入图片 public static void Createsheel2() { WebClien ...