当前位置:网站首页>Leetcode62. 不同路径
Leetcode62. 不同路径
2022-07-28 22:06:00 【Java全栈研发大联盟】
题目传送地址: https://leetcode.cn/problems/unique-paths/
运行效率:
代码如下:
public static int uniquePaths(int m, int n) {
HashMap<String, Integer> map = new HashMap<>();
int i = uniqPathsWithMap(m, n, map);
return i;
}
public static int uniqPathsWithMap(int m, int n, HashMap<String, Integer> map) {
String key = m + ":" + n;
//使用map,提升运行性能
if (map.containsKey(key)) {
return map.get(key);
}
//处理边界情况
if (m == 1 || n == 1) {
return 1;
}
//要想走到(m,n)位置坐标,有2种可能,第一种是从(m-1,n)到(m,n), 第2种是从(m,n-1)到(m,n)
int i = uniqPathsWithMap(m - 1, n, map) + uniqPathsWithMap(m, n - 1, map);
map.put(m + ":" + n, i);
return i;
}
边栏推荐
- Jincang database kingbasees client Programming Interface Guide - ODBC feature support constraints
- Working principle of fastdfs (technical principle)
- VirtualLab基础实验教程-8.傅里叶变换(1)
- 编译原理研究性学习专题 2——递归下降语法分析设计原理与实现
- 浪潮ClusterEngineV4.0 远程命令执行漏洞 CVE-2020-21224
- 2022 R2 mobile pressure vessel filling test question simulation test platform operation
- 剑指 Offer 64. 求1+2+…+n,逻辑运算符短路效应
- 实时数仓:美团基于Flink的实时数仓建设实施
- Asynchronism and synchronization of visa write and read functions by LabVIEW
- 脲酶丨Worthington杰克豆脲酶的特性及测定方案
猜你喜欢

通配符 SSL/TLS 证书

Explanation of history and chemical properties of Worthington ribonuclease B

连接池-归还连接详解(下)

2022 simulated examination platform operation of hoisting machinery command examination questions

新一代超安全蜂窝电池 思皓爱跑上市13.99万元起售

【CNN】为什么CNN的卷积核大小一般都是奇数

Uricase - Characteristics of uricase in Worthington pig liver:

EN 1935建筑五金.单轴铰链—CE认证

器利而工善,以RPA+LCAP赋能企业司库管理数字化升级

编译原理研究性学习专题 2——递归下降语法分析设计原理与实现
随机推荐
hutool官网(hutool好用吗)
Okaleido生态核心权益OKA,尽在聚变Mining模式
Genomic DNA isolation Worthington ribonuclease A
Compatibility description between kingbasees and Oracle (4. SQL)
sql 左连接,内连接 的写法「建议收藏」
Zibo station construction guide (aigler)
Design idea of room inventory in hotel reservation system database
Leetcode64. 最小路径和
Exchange 2013 SSL证书安装文档
迅为IMX6开发板QT系统创建AP热点基于RTL8723-交叉编译iptables
使用Pytorch快速训练网络模型
Blocking queue
Apple's official website is being updated to maintain the apple store. Products such as the iPhone 13 / pro of the Bank of China will enjoy a maximum discount of 600 yuan
深度剖析集成学习Xgboost
RHCE the next day
OpenCV宏定义
Class, leetcode919 -- complete binary tree inserter
2022g3 boiler water treatment test simulation 100 questions simulation test platform operation
Js判断数据类型的4种⽅式
[detailed and super simple] how to use websocket links