当前位置:网站首页>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;
}
边栏推荐
- Jincang database kingbasees client programming interface guide ODBC (2. Overview)
- [detailed and super simple] how to use websocket links
- Hutool official website (is hutool easy to use)
- 深度之眼(十八)——偏导数
- Multisensor fusion positioning (III) -- inertial technology
- Worthington RNA determination detailed introduction
- 2022 G2 power plant boiler stoker examination question bank simulated examination platform operation
- Zabbix 5.0 使用自带Redis模版监控
- 经典的拓扑排序问题——LeetCode207 课程表+LeetCode210 课程表II
- 智能垃圾桶(七)——SG90舵机的介绍与使用(树莓派pico实现)
猜你喜欢

A new generation of ultra safe cellular battery, Sihao aipao, will be available from 139900 yuan

My second uncle is angry and swipes the screen all over the network. How can he cure my spiritual internal friction?

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

基因组 DNA 分离丨Worthington核糖核酸酶A

Jincang database kingbasees client programming interface guide ODBC (2. Overview)

Wildcard ssl/tls certificate

Worthington丨Worthington胰蛋白酶化学性质及相关研究

Solve thread safety problems & singleton mode

Xss.haozi.me range details
![[self] - question brushing - dynamic programming](/img/84/edc683494756d5af755204fe4f4d93.png)
[self] - question brushing - dynamic programming
随机推荐
Jincang database kingbasees client programming interface guide ODBC (5. Development process)
新一代超安全蜂窝电池 思皓爱跑上市13.99万元起售
Exchange 2013 SSL证书安装文档
YOLOV5学习笔记(一)——原理概述
Ape anthropology topic 20
Compatibility description between kingbasees and Oracle (4. SQL)
2022-07-28:以下go语言代码输出什么?A:AA;B:AB;C:BA;D:BB。 package main import ( “fmt“ ) func
脲酶丨Worthington杰克豆脲酶的特性及测定方案
Arm-A53资料「建议收藏」
pip镜像下载
Where is the DP interface of desktop computer (what if the host has no DP interface)
从XSS Payload学习浏览器解码
E-commerce data model design
使用Pytorch快速训练网络模型
台式机dp接口在哪(主机没有dp接口怎么办)
商家对积分体系运营的两个误解
2022 R2 mobile pressure vessel filling test question simulation test platform operation
NPDP考试需要携带什么?文具携带说明
Kingbasees client programming interface guide ODBC (4. Create data source)
Pycharm new project