当前位置:网站首页>February 13, 2022-2-climbing stairs
February 13, 2022-2-climbing stairs
2022-07-06 10:36:00 【Procedural ape does not lose hair 2】
Suppose you're climbing the stairs . need n You can reach the top of the building .
Every time you climb 1 or 2 A stair . How many different ways can you climb to the top of the building ?
Example 1:
Input :n = 2
Output :2
explain : There are two ways to climb to the top .
- 1 rank + 1 rank
- 2 rank
Example 2:
Input :n = 3
Output :3
explain : There are three ways to climb to the top .
- 1 rank + 1 rank + 1 rank
- 1 rank + 2 rank
- 2 rank + 1 rank
Tips :
1 <= n <= 45
java Code :
class Solution {
public int climbStairs(int n) {
if(n ==1 || n ==2) {
return n;
}
// Dynamic programming
int[] dp = new int[n+1];
dp[0] =1;
dp[1] = 1;
for(int i=2;i<=n;i++) {
dp[i] = dp[i-1] + dp[i-2];
}
return dp[n];
}
}
边栏推荐
- Preliminary introduction to C miscellaneous lecture document
- Opencv uses freetype to display Chinese
- 软件测试工程师必备之软技能:结构化思维
- Download and installation of QT Creator
- MySQL26-性能分析工具的使用
- Emotional classification of 1.6 million comments on LSTM based on pytoch
- MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
- 如何搭建接口自动化测试框架?
- Record the first JDBC
- MySQL real battle optimization expert 08 production experience: how to observe the machine performance 360 degrees without dead angle in the process of database pressure test?
猜你喜欢
使用OVF Tool工具从Esxi 6.7中导出虚拟机
[Julia] exit notes - Serial
Record the first JDBC
MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?
数据库中间件_Mycat总结
Mysql26 use of performance analysis tools
基于Pytorch的LSTM实战160万条评论情感分类
【C语言】深度剖析数据存储的底层原理
保姆级手把手教你用C语言写三子棋
Mysql32 lock
随机推荐
Isn't there anyone who doesn't know how to write mine sweeping games in C language
MySQL learning diary (II)
【C语言】深度剖析数据存储的底层原理
[unity] simulate jelly effect (with collision) -- tutorial on using jellysprites plug-in
MySQL24-索引的数据结构
[programmers' English growth path] English learning serial one (verb general tense)
pytorch的Dataset的使用
The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
实现微信公众号H5消息推送的超级详细步骤
实现以form-data参数发送post请求
PyTorch RNN 实战案例_MNIST手写字体识别
Anaconda3 安装cv2
MySQL的存储引擎
保姆级手把手教你用C语言写三子棋
MySQL30-事务基础知识
MySQL21-用户与权限管理
Export virtual machines from esxi 6.7 using OVF tool
Use JUnit unit test & transaction usage
第一篇博客
MySQL29-数据库其它调优策略