当前位置:网站首页>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];
}
}
边栏推荐
猜你喜欢

How to make shell script executable

实现微信公众号H5消息推送的超级详细步骤

Use JUnit unit test & transaction usage

Moteur de stockage mysql23

MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
![14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]](/img/c4/81f00c8b7037b5fb4c5df4d2aa7571.png)
14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]

MySQL32-锁

该不会还有人不懂用C语言写扫雷游戏吧

使用OVF Tool工具从Esxi 6.7中导出虚拟机

A necessary soft skill for Software Test Engineers: structured thinking
随机推荐
Time complexity (see which sentence is executed the most times)
15 medical registration system_ [appointment registration]
Several errors encountered when installing opencv
ZABBIX introduction and installation
Redis集群方案应该怎么做?都有哪些方案?
MySQL transaction log
Super detailed steps for pushing wechat official account H5 messages
Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
用于实时端到端文本识别的自适应Bezier曲线网络
MySQL24-索引的数据结构
Database middleware_ MYCAT summary
MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
MySQL21-用户与权限管理
Good blog good material record link
Solve the problem of remote connection to MySQL under Linux in Windows
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
Mysql36 database backup and recovery
Export virtual machines from esxi 6.7 using OVF tool
Mysql26 use of performance analysis tools
Jar runs with error no main manifest attribute