当前位置:网站首页>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;
}
边栏推荐
- pip镜像下载
- 实时数仓:网易严选基于Flink的实时数仓实践
- VMware VCSA 7.0 Install
- 宝塔 phpmyadmin未授权访问漏洞
- Zibo station construction guide (aigler)
- Exchange 2013 SSL证书安装文档
- Jincang database kingbasees client programming interface guide ODBC (2. Overview)
- Uricase - Characteristics of uricase in Worthington pig liver:
- 通配符 SSL/TLS 证书
- 零视科技 H5S视频平台 GetUserInfo 信息泄漏漏洞 CNVD-2020-67113
猜你喜欢

Worthington核糖核酸测定详细攻略

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

多传感器融合定位(一)——3D激光里程计

2022 R2 mobile pressure vessel filling test question simulation test platform operation

剑指 Offer 55 - I. 二叉树的深度

Class, leetcode919 -- complete binary tree inserter

Multisensor fusion positioning (III) -- inertial technology

2022 welder (Junior) work license questions and answers

控件 圆角描边 MaterialShapeDrawable

Codeforces Round #810 (Div. 2) A - C
随机推荐
Leetcode 763. partition labels divide alphabetic intervals (medium)
Ape anthropology topic 20
pip镜像下载
Equipped with a new generation of ultra safe cellular batteries, Sihao aipao is available from 139900 yuan
Multi sensor fusion positioning (II) -- map based positioning
Urease -- Characteristics and determination scheme of Worthington jack bean urease
RHCE the next day
pycharm新建项目
websocket心跳机制(保活机制)
SQL left connection, internal connection writing method "recommended collection"
深度剖析集成学习Adaboost
Jincang database kingbasees client programming interface guide ODBC (2. Overview)
控件 圆角描边 MaterialShapeDrawable
Asynchronism and synchronization of visa write and read functions by LabVIEW
宝塔 phpmyadmin未授权访问漏洞
数仓:Doris在美团的应用实践
PowerCL 批量创建及管理虚拟交换机
Mongodb index add, view, export, delete
DevOps在物联网解决方案中的应用
PowerCLi 批量添加esxi到vCenter