当前位置:网站首页>Leetcode70. 爬楼梯
Leetcode70. 爬楼梯
2022-07-30 01:02:00 【Java全栈研发大联盟】
题目传送地址: https://leetcode.cn/problems/climbing-stairs/
运行效率:
代码如下:
public static int climbStairs(int n) {
HashMap<Integer, Integer> map = new HashMap<>();
int i = climbStairsWithMap(n, map);
return i;
}
//用map可以提升查询性能,加快查询速度
public static int climbStairsWithMap(int n, HashMap<Integer,Integer> map){
if(map.containsKey(n)){
return map.get(n);
}
//处理边界条件
if(n==1){
return 1;
}
if(n==2){
return 2;
}
//要爬到第n阶,可以有2种办法,第一种是从n-1阶跳一格到n阶 第二种是从n-2阶跳2格到n阶
int i = climbStairsWithMap(n - 1, map) + climbStairsWithMap(n - 2, map);
map.put(n,i);
return i;
}
边栏推荐
猜你喜欢

重新定义分析 - EventBridge 实时事件分析平台发布

【MySQL系列】MySQL数据库基础

How many ways does Selenium upload files?I don't believe you have me

string replace spaces

泰克Tektronix示波器软件TDS1012|TDS2002|TDS2004上位机软件NS-Scope

Worthington's tried and tested cell isolation system protocols

Unity笔记——FairyGUI
![[Best training DAY16] KC's Can [Dynamic programming]](/img/60/26280222faf72bd94c654b1810381d.png)
[Best training DAY16] KC's Can [Dynamic programming]

液压滑环的应用介绍

自学HarmonyOS应用开发(53)- 获取当前位置
随机推荐
2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。
Linux - install MySQL (detailed tutorial)
Navicat error: 1045-Access denied for user [email protected](using passwordYES)
Douyin short video traffic acquisition strategy, mastering these will definitely be a hit
Detailed explanation of nacos cluster configuration
Navicat报错:1045-Access denied for user [email protected](using passwordYES)
News text classification
Running a Fabric Application
SSM integration case
验证框架-01
Since the media how to write a short video title?Three hot style title, let your video gain more traffic
【LeetCode每日一题】——637.二叉树的层平均值
canvas 中如何实现物体的框选(六)
[Flutter] Flutter preloading of mixed development solves the problem of slow page loading for the first time
二维数组的查找
4 hotspot inquiry networks necessary for new media operations
百度智能云章淼:详解企业级七层负载均衡开源软件BFE
Worthington Dissociation Enzymes: Trypsin and Frequently Asked Questions
Worthington dissociating enzyme: detailed analysis of neutral protease (dispase)
专心致志做事情