当前位置:网站首页>[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边栏推荐
- Analyze the maker education path integrating the essence of discipline
- Some views on libco
- Oracle data integrity
- The real topic of the 11th provincial competition of Bluebridge cup 2020 - crop hybridization
- ESP8266 RC522
- 关于Unity一般的输入操作方式
- 分割链表[先取next再斩断链表防止断链]
- About the general input operation mode of unity
- Left join displays the specified value when the left join matching data is null
- For the first time in more than 20 years! CVPR best student thesis awarded to Chinese college students!
猜你喜欢

解决IDEA:Class ‘XXX‘ not found in module ‘XXX‘

Koa koa-combine-routers 分路由管理

XJY-220/43AC220V静态信号继电器

Exercises on recursion in C language

Q play soft large toast to bring more comfortable sleep

人穷志不短,穷学生也能玩转树莓派

Share your own terminal DIY display banner

5. TPM module initialization

Hoo research | coinwave production - nym: building the next generation privacy infrastructure

蒹葭苍苍,白露为霜。
随机推荐
机器人编程的培训学科类原理
1175. Prime Arrangements
Tcp/ip protocol stack, about TCP_ RST | TCP_ ACK correct attitude
User defined annotation implementation verification
软件开发完整流程
How to do the performance pressure test of "Health Code"
[LeetCode] 爬楼梯【70】
DLS-20型双位置继电器 220VDC
Solve idea:class' xxx 'not found in module' xxx‘
Shift operators
Golang treasure house recommendation
【学习笔记】倍增 + 二分
(learning power + thinking power) x action power, summary of flywheel effect on the growth of technicians
js中把数字转换成汉字输出
Web interface testing of software testing
[original] PLSQL index sorting optimization
闭锁继电器YDB-100、100V
A proper job is a good job
06. on several ways of redis persistence
History of deep learning