当前位置:网站首页>[leetcode] climb stairs [70]
[leetcode] climb stairs [70]
2022-07-01 01:20:00 【When Camellia blossoms.】
problem : Suppose you're climbing the stairs , need n To reach the roof . 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
# solution 1
def climbStairs(n):
if n <= 2:
return n
else:
return climbStairs(n-1) + climbStairs(n-2)
# solution 2
def climbStairs(n):
arr = [1,2]
if n <= 2:
return arr[n - 1]
else:
# n Greater than 2
for i in range(2,n):
arr.append(arr[i - 1] + arr[i - 2])
return arr[n - 1]
climbStairs(2) # 2
climbStairs(3) # 3边栏推荐
- 解析融合学科本质的创客教育路径
- DLS-42/6-4 DC110V双位置继电器
- 软硬件基础知识学习--小日记(1)
- 06. on several ways of redis persistence
- Unhandled Exception: MissingPluginException(No implementation found for method launch on channel)
- Dls-20 double position relay 220VDC
- Day31-t1380-2022-02-15-not answer by yourself
- MATLAB 最远点采样(FPS改进版)
- [original] PLSQL index sorting optimization
- 奇偶链表[链表操作的两种大方向]
猜你喜欢
![奇偶链表[链表操作的两种大方向]](/img/4e/ce860bc172bb75f456427ba26a7842.png)
奇偶链表[链表操作的两种大方向]

Oracle temporary table explanation

Vnctf 2022 cm CM1 re reproduction

友盟(软件异常实时监听的好帮手:Crash)接入教程(有点基础的小白最易学的教程)

孔乙己第一问之服务通信知多少?

Training discipline principle of robot programming

Analysis of blocktoken principle

集群与LVS介绍及原理解析

Share your own terminal DIY display banner

Installing mongodb database in Windows Environment
随机推荐
How to do the performance pressure test of "Health Code"
5. TPM module initialization
Q弹松软的大号吐司,带来更舒服的睡眠
06. on several ways of redis persistence
Impact relay zc-23/dc220v
What is product thinking
A letter to 5000 fans!
Using asyncio for concurrency
High quality pump SolidWorks model material recommended, not to be missed
Day31-t1380-2022-02-15-not answer by yourself
Left join displays the specified value when the left join matching data is null
Oracle table creation and management
Web compatibility testing of software testing
DLS-42/6-4 DC110V双位置继电器
关于Unity一般的输入操作方式
ESP8266 RC522
Solve idea:class' xxx 'not found in module' xxx‘
How to scroll uitableview to a specific position - how to scroll uitableview to specific position
Usage of C set
Listview in flutter application development