当前位置:网站首页>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];
}
}
边栏推荐
- C miscellaneous dynamic linked list operation
- 软件测试工程师必备之软技能:结构化思维
- Mysql23 storage engine
- Mysql36 database backup and recovery
- 13 medical registration system_ [wechat login]
- Mysql27 index optimization and query optimization
- Mysql32 lock
- 在jupyter NoteBook使用Pytorch进行MNIST实现
- MySQL combat optimization expert 09 production experience: how to deploy a monitoring system for a database in a production environment?
- Water and rain condition monitoring reservoir water and rain condition online monitoring
猜你喜欢
随机推荐
Windchill configure remote Oracle database connection
使用OVF Tool工具从Esxi 6.7中导出虚拟机
[after reading the series of must know] one of how to realize app automation without programming (preparation)
MySQL实战优化高手06 生产经验:互联网公司的生产环境数据库是如何进行性能测试的?
MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
Global and Chinese market of operational amplifier 2022-2028: Research Report on technology, participants, trends, market size and share
Isn't there anyone who doesn't know how to write mine sweeping games in C language
MySQL27-索引优化与查询优化
Mysql30 transaction Basics
【C语言】深度剖析数据存储的底层原理
MySQL36-数据库备份与恢复
MySQL底层的逻辑架构
Mysql27 index optimization and query optimization
Just remember Balabala
Google login prompt error code 12501
A necessary soft skill for Software Test Engineers: structured thinking
C miscellaneous two-way circular linked list
如何搭建接口自动化测试框架?
PyTorch RNN 实战案例_MNIST手写字体识别
Mysql34 other database logs









