当前位置:网站首页>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;
}
边栏推荐
- Running a Fabric Application
- Recommendation system: collection of user "behavioral data" [use Kafka and Cassandra to process data] [if it overlaps with business data, it also needs to be collected independently]
- Nacos micro service ~ Nacos 】 【 configuration of the center
- Fabric Private Data Case
- 3 tips for using hot events to create press releases?A must-see for self-media people
- 裁员趋势下的大厂面试:“字节跳动”
- 二叉排序树(C语言)
- [Best training DAY16] KC's Can [Dynamic programming]
- [Experience] Experience Summary - Lessons Learned
- 重新定义分析 - EventBridge 实时事件分析平台发布
猜你喜欢

基于SSM开发实现校园疫情防控管理系统

Weekly recommended short video: What is R&D efficiency?It can achieve anti "involution"?

【MySQL系列】MySQL数据库基础

LeetCode/Scala - without the firstborn of the string of characters, the longest text string back

工厂模式

Linux-安装MySQL(详细教程)

CMake Tutorial Tour (1)_Basic starting point

Worthington Optimized Technology: Cell Quantification

3 tips for using hot events to create press releases?A must-see for self-media people
![[Best training DAY16] KC's Can [Dynamic programming]](/img/60/26280222faf72bd94c654b1810381d.png)
[Best training DAY16] KC's Can [Dynamic programming]
随机推荐
7.28
Baidu Intelligent Cloud Zhangmiao: Detailed explanation of enterprise-level seven-layer load balancing open source software BFE
自学HarmonyOS应用开发(56)- 用Service保证应用在后台持续运行
【Vmware NSX-V基本架构及组件安装】
帽式滑环的工作原理
STM32 - OLED display experiment
LABVIEW详细介绍:LABVIEW是什么软件?都可以干什么?
LeetCode / Scala - 无重复字符最长子串 ,最长回文子串
Recurrent Neural Network (RNN)
专心致志做事情
exness:美国GDP萎缩,日元反弹受捧
2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。
推荐系统:特征工程、常用特征
某团实习面经
更换可执行文件glibc版本的某一次挣扎
遇到bug的解决办法,测试再也不背锅了
泰克Tektronix示波器软件TDS520|TDS1001|TDS1002上位机软件NS-Scope
@RequestParam注解的详细介绍
The range of motion of the robot
Fabric 私有数据案例