当前位置:网站首页>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];
}
}
边栏推荐
- 软件测试工程师发展规划路线
- 15 medical registration system_ [appointment registration]
- 软件测试工程师必备之软技能:结构化思维
- MySQL35-主从复制
- Texttext data enhancement method data argument
- How to make shell script executable
- Typescript入门教程(B站黑马程序员)
- 高并发系统的限流方案研究,其实限流实现也不复杂
- Preliminary introduction to C miscellaneous lecture document
- Unicode decodeerror: 'UTF-8' codec can't decode byte 0xd0 in position 0 successfully resolved
猜你喜欢

用于实时端到端文本识别的自适应Bezier曲线网络

C miscellaneous dynamic linked list operation

数据库中间件_Mycat总结

Mysql25 index creation and design principles

Water and rain condition monitoring reservoir water and rain condition online monitoring

The underlying logical architecture of MySQL

PyTorch RNN 实战案例_MNIST手写字体识别

软件测试工程师必备之软技能:结构化思维

How to make shell script executable

MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
随机推荐
MySQL实战优化高手06 生产经验:互联网公司的生产环境数据库是如何进行性能测试的?
Advantages and disadvantages of evaluation methods
Redis集群方案应该怎么做?都有哪些方案?
Security design verification of API interface: ticket, signature, timestamp
MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?
If someone asks you about the consistency of database cache, send this article directly to him
Database middleware_ MYCAT summary
MySQL24-索引的数据结构
Vscode common instructions
MySQL transaction log
【C语言】深度剖析数据存储的底层原理
Security design verification of API interface: ticket, signature, timestamp
Mysql35 master slave replication
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
如何搭建接口自动化测试框架?
Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
MySQL36-数据库备份与恢复
MySQL ERROR 1040: Too many connections
百度百科数据爬取及内容分类识别
基于Pytorch肺部感染识别案例(采用ResNet网络结构)