当前位置:网站首页>31. Climb stairs
31. Climb stairs
2022-07-24 12:46:00 【Little happy】
70. climb stairs
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 ?
** Be careful :** Given n Is a positive integer .
Example 1:
Input : 2
Output : 2
explain : There are two ways to climb to the top .
1. 1 rank + 1 rank
2. 2 rank
Example 2:
Input : 3
Output : 3
explain : There are three ways to climb to the top .
1. 1 rank + 1 rank + 1 rank
2. 1 rank + 2 rank
3. 2 rank + 1 rank
Fibonacci sequence
class Solution {
public int climbStairs(int n) {
int a = 0;
int b = 1;
int res = 0;
for(int i=1;i<=n;i++){
int c = a;
a = b;
b = c +b;
}
return b;
}
}
class Solution {
public int climbStairs(int n) {
int[] f = new int[n+1];
f[0] = 1;
f[1] = 1;
for(int i=2;i<=n;i++){
f[i]=f[i-1]+f[i-2];
}
return f[n];
}
}
边栏推荐
- SSM在线租房售房平台多城市版本
- Raspberry pie self built NAS cloud disk -- automatic data backup
- 基于Kubernetes v1.24.0的集群搭建(二)
- 让一套代码完美适配各种屏幕
- 【Rust】引用和借用,字符串切片 (slice) 类型 (&str)——Rust语言基础12
- [C language] dynamic memory management
- How to mount NFS shares using autofs
- Efficientformer: lightweight vit backbone
- setAttribute、getAttribute、removeAttribute
- Unity rotation test
猜你喜欢

Support liuhaiping

Vscode solves the problem of terminal Chinese garbled code

ThinkPHP realizes database backup

Basic SQL server operation problems - only when lists are used and identity_ Only when insert is on can the display value be set for the identification column in the table

Installation and deployment of ansible

The setting float cannot float above the previous Div

基于Kubernetes v1.24.0的集群搭建(二)

leetcode第 302 场周赛复盘

Wechat applet - drawing dashboard

Nacos deployment
随机推荐
Industry insight | how to better build a data center? It and business should "go together"
2022.07.15 summer training personal qualifying (10)
Proxy
1.9. touch pad test
for mysql
Is there a free and commercially available website for US media video clips?
What kind of experience is a monthly salary of 30000 yuan? Can we achieve this level as we media
Buckle exercise - 32 divided into k equal subsets
Wechat applet generates QR code
Basic SQL server operation problems - only when lists are used and identity_ Only when insert is on can the display value be set for the identification column in the table
Force deduction exercise - 26 split array into continuous subsequences
The price of domestic flagship mobile phones is nearly 6000, but they can't even beat iphone12. It's clear who users choose
月薪 3万人民币是一种怎样的体验?做自媒体可以达到这种水平吗
【C语言】动态内存管理
使用Jenkins搭建CI服务器
Behind the rapid growth, Huawei cloud Wulanchabu data center is the green way
SSH服务突然连接不了案例总结
New applications of iSCSI and separation of storage services of NFS
STM32 - Fundamentals of C language
权限系统就该这么设计,yyds