当前位置:网站首页>Leetcode63. 不同路径 II
Leetcode63. 不同路径 II
2022-07-28 22:06:00 【Java全栈研发大联盟】
题目传送地址:https://leetcode.cn/problems/unique-paths-ii/
运行效率:
代码如下:
public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
int m = obstacleGrid.length-1;
int n = obstacleGrid[0].length-1;
return uniquePaths(m, n, obstacleGrid);
}
public static int uniquePaths(int m, int n, int[][] obstacleGrid) {
HashMap<String, Integer> map = new HashMap<>();
return uniqPathsWithMap(m, n, obstacleGrid, map);
}
public static int uniqPathsWithMap(int m, int n, int[][] obstacleGrid, HashMap<String, Integer> map) {
if (obstacleGrid[m][n] == 1) {
return 0;
}
String key = m + ":" + n;
if (map.containsKey(key)) {
return map.get(key);
}
//处理边界情况
if (m == 0) {
while (n>0){
if(obstacleGrid[0][n-1]==1){
return 0;
}
n--;
}
return 1;
}
if(n==0){
while (m>0){
if(obstacleGrid[m-1][0]==1){
return 0;
}
m--;
}
return 1;
}
//要想走到(m,n)位置坐标,有2种可能,第一种是从(m-1,n)到(m,n), 第2种是从(m,n-1)到(m,n)
int i = uniqPathsWithMap(m - 1, n, obstacleGrid, map) + uniqPathsWithMap(m, n - 1, obstacleGrid, map);
map.put(m + ":" + n, i);
return i;
}
边栏推荐
- 简述分组密码的加密分组链接模式的工作原理及其特点(密码学移位密码加密解密)
- Urease -- Characteristics and determination scheme of Worthington jack bean urease
- 数据中台的那些“经验与陷阱”
- 2022t elevator repair examination questions and simulation examination
- 台式机dp接口在哪(主机没有dp接口怎么办)
- 零视科技 H5S视频平台 GetUserInfo 信息泄漏漏洞 CNVD-2020-67113
- 深度剖析集成学习Xgboost(续)
- Deep analysis of integrated learning gbdt
- 什么是驱动程序签名,驱动程序如何获取数字签名?
- [data mining engineer - written examination] Dahua shares in 2022
猜你喜欢

解决线程安全问题&&单例模式

什么是驱动程序签名,驱动程序如何获取数字签名?

多传感器融合定位(二)——基于地图的定位

Uricase - Characteristics of uricase in Worthington pig liver:

剑指 Offer 64. 求1+2+…+n,逻辑运算符短路效应

脲酶丨Worthington杰克豆脲酶的特性及测定方案

SAP oracle 复制新实例后数据库远程连接报错 ora-01031

Multisensor fusion positioning (III) -- inertial technology

Machine learning problem notes

EN 1935建筑五金.单轴铰链—CE认证
随机推荐
编译原理研究性学习专题 2——递归下降语法分析设计原理与实现
Compatibility description between kingbasees and Oracle (4. SQL)
The computer doesn't know what to uninstall, can't open the calculator, can't edit screenshots, can't open txt files, and so on
Design idea of room inventory in hotel reservation system database
Explanation of history and chemical properties of Worthington ribonuclease B
Tyrosine decarboxylase -- characteristics of tyrosine decarboxylase of Streptococcus faecalis in Worthington
使用Pytorch快速训练网络模型
[self] - brush questions BFS
台式机dp接口在哪(主机没有dp接口怎么办)
Compatibility description between kingbasees and Oracle (2. Data type)
连接池-归还连接详解(下)
E-commerce data model design
添加构建依赖项报错
2022-07-28:以下go语言代码输出什么?A:AA;B:AB;C:BA;D:BB。 package main import ( “fmt“ ) func
阻塞式队列
PHP 海报二维码合成
Worthington RNA determination detailed introduction
尿酸酶丨Worthington猪肝尿酸酶的特征:
Okaleido生态核心权益OKA,尽在聚变Mining模式
Jincang database kingbasees client programming interface guide ODBC (5. Development process)