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 ...
随机推荐
- Javac中对import关键字进行的处理
参考文章: (1)关于类的符号输入过程第二篇 ImportScope中存储的为ImportEntry,继承了Scope.Entry类并且多定义了个origin属性,也就是符号的最终来源.除此之外还对g ...
- JavaScript -- Style
-----055-Style.html----- <!DOCTYPE html> <html> <head> <meta http-equiv="c ...
- Window下JDK、Tomcat、eclipse安装与配置
今天项目组开会,由于.Net平台的限制无法满足现有业务需求,项目计划从.Net平台转Java平台,采用Java+Spark+Hadoop,之前关于Java和Hadoop的书也买的有只是平时看的少,最近 ...
- Microsoft Office MIME Types
经常需要查找Microsoft Office MIME Types,终于在MSDN网上找到,摘录如下,以备查阅与参考:http://blogs.msdn.com/b/vsofficedeveloper ...
- [android] fragment的生命周期和通讯
重写一下生命周期方法 所有的fragment都是依附于activity的,只有当activity显示出来的时候,fragment才能够创建上去 onAttach,当附加到activity上的时候 on ...
- 【公众号转载】超详细 Nginx 极简教程,傻瓜一看也会!
什么是Nginx? Nginx (engine x) 是一款轻量级的Web 服务器 .反向代理服务器及电子邮件(IMAP/POP3)代理服务器. 什么是反向代理? 反向代理(Reverse Proxy ...
- Gold Rush(hnu13249)
Gold Rush Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB Total submit users: 15 ...
- POJ3694(KB9-D 割边+LCA)
Network Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10371 Accepted: 3853 Descript ...
- JavaScript--表单处理(27)
一 表单介绍 // 在HTML中,表单是由<form>元素来表示的,而在JavaScript中,表单对应的则是HTMLFormElement类型; // HTMLFormElement继承 ...
- web自动化开发环境配置详解
1.安装 nodejs Grunt和所有grunt插件都是基于nodejs来运行的, https://nodejs.org/ 安装完成之后在终端 node -v 查看安装版本 2.安装 grunt-C ...