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的更多相关文章

  1. 【LeetCode练习题】Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

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

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

  3. 【LeetCode】63. Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

  4. 【LeetCode】063. Unique Paths II

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

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

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

  6. LeetCode OJ 63. Unique Paths II

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

  7. [leetcode DP]63. Unique Paths II

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

  8. LeetCode OJ:Unique Paths II(唯一路径II)

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

  9. leetcode@ [62/63] Unique Paths II

    class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleG ...

随机推荐

  1. Mac 下使用 brew 安装软件

    官网:http://brew.sh/安装 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/m ...

  2. OAuth 2.0 安全案例回顾

    原文:http://drops.wooyun.org/papers/598 0x00 背景 纵观账号互通发展史,可以发现OAuth比起其它协议(如OpenID)更流行的原因是,业务双方不仅要求账号本身 ...

  3. 走进javascript——被忽视的DOM方法和属性

    isEqualNode() isEqualNode方法可以用来判断两个DOM节点是否相同,给我的第一感觉是没用,因为两个DOM的比较很容易让人想成是字符串的比较,心想直接用两个等号不就可以了吗,但马上 ...

  4. top 动态查看进程

    top 统计信息前五行是系统整体的统计信息 1.第一行是任务队列信息 同uptime质性命令结果一样. 06:47:11 up 6:39, 3 users, load average: 0.00, 0 ...

  5. 微信小程序——动态渲染页面、路径传参

      1.动态渲染页面.改变css.样式必须setData渲染过去   this.setData({ userInfo: app.globalData.userInfo, token: app.glob ...

  6. Python模块: 文件和目录os+shutil

    一 常用函数 os模块 os.sep 表示默认的文件路径分隔符,windows为\, linux为/os.walk(spath): 用来遍历目录下的文件和子目录os.listdir(dirname): ...

  7. 基于卷积神经网络的手写数字识别分类(Tensorflow)

    import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...

  8. MVC应用程序,动态创建单选列表(RadioButtonList)

    单选列表是多个选项,让用户选择一个.MVC应用程序开发中,少之不了.下面就来练习之个小功能. 这个练习,Insus.NET想实现一个日期显示的格式.在MVC中,得需从model开始创建: 再创建一个E ...

  9. winform程序内存不足或假死的问题

    最近一直在写一个winform程序,对各类文档文件,以及压缩包的内容进行关键字检测. 模型出来之后,执行了一下,发现连续测试后,会有内存不足的问题,导致程序面假死.脑袋懵逼了两天. 回头看我的变量容器 ...

  10. Spring源码分析:Bean加载流程概览及配置文件读取

    很多朋友可能想看Spring源码,但是不知道应当如何入手去看,这个可以理解:Java开发者通常从事的都是Java Web的工作,对于程序员来说,一个Web项目用到Spring,只是配置一下配置文件而已 ...