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 ...
随机推荐
- 磁盘分区以及Linux目录挂载详解
一.背景 一直以来,对于磁盘的分区以及Linux目录挂载的概念都不是很清晰,现在趁着春暖花开周末在家没事就研究了下它们,现在来分享我的理解. 二.概念详解 1.磁盘分区 磁盘分区是把物理的磁盘空间按照 ...
- 【原】ATI显卡设置双显示器
Ubuntu 12.04系统下加上增加一个显示器后,一直只能镜像显示,或只能用笔记本的屏幕显示,另一个屏幕无法使用了,上网搜索了一下解决办法,通过下面的方法可以解决问题: 编辑/etc/X11/xor ...
- JavaScript -- Location
-----043-Location.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=&quo ...
- C#基础篇三流程控制2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace P01R ...
- 高可用Hadoop平台-答疑篇
1.概述 这篇博客不涉及到具体的编码,只是解答最近一些朋友心中的疑惑.最近,一些朋友和网友纷纷私密我,我总结了一下,疑问大致包含以下几点: 我学 Hadoop 后能从事什么岗位? 在遇到问题,我该如何 ...
- mongodb索引--1亿条记录的查询从55.7秒到毫秒级别<补充版>
从头开始,验证mongodb的索引的好处.(window7环境下) 下载mongodb服务器,并解压到d盘,并使用以下命令启动 mongod --dbpath D:\mongodb\data mong ...
- asp.net MVC 的处理流程
之前把笔记都放在空间日志中隐藏起来,今天看到这句话:作为经常从网上索取免费资料的一员,要有回报的思想,也为了让更多的人少走些弯路,想想自己不能这么自私,所以把空间日志搬到博客园来.闲话不说,直接开始. ...
- UIKit 框架之UIControl
前面的UIWebView.UIImageView这些都是视图,显示为主,与用户交互较少,最多也就是通过UIResponder与用户交互.但这样会很麻烦,还要判断点击次数等等问题,那问题就来了:OC中怎 ...
- ASP.NET MVC显示UserControl控件(扩展篇)
昨晚Insus.NET有怀旧一下<念念不忘,ASP.NET MVC显示WebForm网页或UserControl控件>http://www.cnblogs.com/insus/p/3641 ...
- ADO.NET 【类库】【与数据库的连接】
ADO.NET是什么,有什么用 数据库访问技术 ado.net可让开发人员以一致的方式存取资料来源, 资料共用的消费者应用程序可使用ado.net 来连接至这些资料来源,并且撷取.处理及更新其中所含的 ...