当前位置:网站首页>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];
}
}
边栏推荐
- MySQL22-逻辑架构
- Anaconda3 installation CV2
- MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?
- 软件测试工程师发展规划路线
- Global and Chinese market for intravenous catheter sets and accessories 2022-2028: Research Report on technology, participants, trends, market size and share
- What is the difference between TCP and UDP?
- First blog
- MySQL实战优化高手05 生产经验:真实生产环境下的数据库机器配置如何规划?
- Technology | diverse substrate formats
- Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
猜你喜欢
Mysql34 other database logs
软件测试工程师必备之软技能:结构化思维
How to build an interface automation testing framework?
MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
Moteur de stockage mysql23
MySQL23-存储引擎
MySQL21-用户与权限管理
Redis集群方案应该怎么做?都有哪些方案?
Mysql27 - Optimisation des index et des requêtes
随机推荐
[unity] simulate jelly effect (with collision) -- tutorial on using jellysprites plug-in
Download and installation of QT Creator
[after reading the series] how to realize app automation without programming (automatically start Kwai APP)
Opencv uses freetype to display Chinese
Solve the problem of remote connection to MySQL under Linux in Windows
Windchill配置远程Oracle数据库连接
Chrome浏览器端跨域不能访问问题处理办法
Mysql35 master slave replication
MySQL36-数据库备份与恢复
[C language] deeply analyze the underlying principle of data storage
MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
MySQL29-数据库其它调优策略
Super detailed steps for pushing wechat official account H5 messages
Global and Chinese market for intravenous catheter sets and accessories 2022-2028: Research Report on technology, participants, trends, market size and share
[paper reading notes] - cryptographic analysis of short RSA secret exponents
Use JUnit unit test & transaction usage
MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
Security design verification of API interface: ticket, signature, timestamp
MNIST implementation using pytoch in jupyter notebook
13 medical registration system_ [wechat login]