当前位置:网站首页>Force buckle - 70 climb stairs
Force buckle - 70 climb stairs
2022-04-23 11:47:00 【Node_ Su】


To get to the current staircase , It can be downloaded from n-1 and n-2 When the stairs get
First , Define the initial state
then , Recursion of previous state
Last , Leave the rest to the code
Overtime
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
memo = [-1] * (n+1)
if n <= 2:
return n
if memo[n] != -1:
return memo[n]
memo[n] = self.climbStairs(n - 1) + self.climbStairs(n - 2)
return memo[n]
No timeout : Consider not using functions , Direct value storage
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
if n <= 2:
return n
dp_2 = 1 # It means dp-2
dp_1 = 2
for i in range(3, n + 1):
res = dp_2 + dp_1
dp_2 = dp_1
dp_1 = res
i = i + 1
return dp_1
版权声明
本文为[Node_ Su]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231138314631.html
边栏推荐
- MySQL 的主从复制配置
- WIN10 启动后花屏
- AcWing 1874. 哞加密(枚举,哈希)
- Laravel增加自定义助手函数
- Nacos Basics (5): getting started with Nacos configuration
- 解析性能良好的机器人使用守则
- Overall plan management mode in maker Education
- How Im expressions work (5.3)
- qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
- 零钱兑换II——【LeetCode】
猜你喜欢

激活函数之阶跃函数

解析性能良好的机器人使用守则

Redis learning 5 - high concurrency distributed lock practice

力扣-70.爬楼梯

Share two practical shell scripts

Advanced file IO of system programming (13) -- IO multiplexing - Select

How to count fixed assets and how to generate an asset count report with one click

WIN10 启动后花屏

激活函数之sigmoid函数

Database design of forum system
随机推荐
[web daily practice] eight color puzzle (float)
Interpreting the art created by robots
redis优化系列(二)Redis主从原理、主从常用配置
Application of remote integrated monitoring system in power distribution room in 10kV prefabricated cabin project
ImportError: libX11. so. 6: cannot open shared object file: No such file or directory
解析性能良好的机器人使用守则
积极参与中学机器人竞赛的意义
Purpose of IM expression (IM 5.2)
golang之笔试题&面试题01
Chapter 4 is a tutorial on forced filling of in memory objects with IM enabled filling objects (IM 4.7)
用户接口和IM表达式(IM 5.6)
How the database fills in IM expressions (IM 5.4)
How Im expressions work (5.3)
Interpretation of biological recognition in robot programming course
一文详解头部位姿估计【收藏好文】
Nacos Basics (5): getting started with Nacos configuration
Summary of the relationship among GPU, CUDA and cudnn
1.Electron开发环境搭建
Im architecture: CPU architecture: SIMD vector processing (im-2.3)
MQ is easy to use in laravel