[leetcode]Unique Paths II
>这道题目和上一题基本是一样的。只需要检测现在正在处理的那个单位是不是不可通过的,如果是就直接让这个单元格=0,也就是没有路径可以到右下角就好了。
代码如下:
public class Solution {public int uniquePathsWithObstacles(int[][] obstacleGrid) {int m=obstacleGrid.length;int n=obstacleGrid[0].length;int[][] a=new int[m][n];if(obstacleGrid[m-1][n-1]==0)a[m-1][n-1]=1;elsea[m-1][n-1]=0;//a[m-2][n-1]=1;//a[m-1][n-2]=1;for(int row=m-1;row>=0;row--){for(int col=n-1;col>=0;col--){if((row==m-1&&col==n-1) || obstacleGrid[row][col]==1)continue;if(row==m-1){a[row][col]=a[row][col+1];}else if(col==n-1)a[row][col]=a[row+1][col];else a[row][col]=a[row][col+1]+a[row+1][col]; }}return a[0][0];}
}
[leetcode]Unique Paths II相关推荐
- [Lintcode]115. Unique Paths II/[Leetcode]63. Unique Paths II
115. Unique Paths II/63. Unique Paths II 本题难度: Easy/Medium Topic: Dynamic Programming Description Fo ...
- 【动态规划】LeetCode 63. Unique Paths II
LeetCode 63. Unique Paths II Solution1:我的答案 在哪里做过这题? class Solution { public:int uniquePathsWithObst ...
- LeetCode Unique Paths
原题链接在这里:https://leetcode.com/problems/unique-paths/ 题目: A robot is located at the top-left corner of ...
- 63. Unique Paths II and 64. Minimum Path Sum
文章目录 1 63 Unique Paths II 1.1 题目描述 1.2 动态规划解决 2 64. Minimum Path Sum 2.1 题目理解 2.2 动态规划 这一遍刷dp的题目就很轻松 ...
- LeetCode | Unique Paths I,II
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- Unique Paths II leetcode java
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- [LeetCode]--63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [LeetCode][Java] Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- C#LeetCode刷题之#63-不同路径 II(Unique Paths II)
目录 问题 示例 分析 问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3682 访问. 一个机器人位于一个 m x ...
最新文章
- request获取数据的几种方法
- 生产者与消费者(二)---await与 signal
- Oracle自动备份脚本(Linux)
- freemarker写select组件报错总结(二)
- 初中数学503个必考知识点_2020年中考数学必考知识点公布,考生高分、满分提分必备神器...
- 原作者出局!Faker.js已被社区控制。。
- (转)hibernate-5.0.7+struts-2.3.24+spring-4.2.4三大框架整合
- npm收录了哪些包_手把手教你制作一个小而美丽的 npm 包并发布
- linux虚拟arm环境环境,Ubuntu 模拟ARM开发环境
- Django的Ajax加额外操作
- ubuntu启动时的初始化信息二
- [渝粤教育] 西南石油大学 岩体力学 参考 资料
- Python使用wordcloud做词云
- matlab预测误差,Matlab的神经网络预测误差比较大,该怎样调整
- 数字体育进入黄金窗口期
- 联通光猫CUAdmin获取
- 阿里云CDN和全站加速区别在哪?使用有感
- 写给父亲的语音计算器(加减乘除的处理C#,三)
- java 序列化理解_对Java Serializable(序列化)的理解和总结(二)
- python安装cfgrib读取grib数据
热门文章
- IT土鳖混外企(一)------面试
- 微软Project项目管理软件简介
- html手机端在线制作,HTML5制作,手机H5页面制作,H5炫酷效果,前端制作 | 纬博赛特...
- 【数据分析】:搭建数据分析业务工作流程
- 转载:js和as间的交互
- 解决win10内存占用逐渐变大(亲测有效)
- Matlab如何删除矩阵中的零元素,重新整理不等行的矩阵
- java poi之操作ppt\pptx
- TurboLaunch启动后无法显示的问题
- 用python监控A股股票波动并发送预警邮件_V3