当前位置:网站首页>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
边栏推荐
- Laravel admin time range selector daterange default value problem
- IM表达式如何工作(5.3)
- 科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
- Blog post navigation (real-time update)
- 一文详解头部位姿估计【收藏好文】
- MySQL 的主从复制配置
- Who said you should know PS? This open-source artifact can also be pulled in batch, and the effect is outstanding!
- ImportError: libX11.so.6: cannot open shared object file: No such file or directory
- Laravel adds custom helper functions
- 《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
猜你喜欢
Interpreting the art created by robots
Tensorflow使用keras创建神经网络的方法
On the integration of steam education in early childhood education
WIN10 启动后花屏
初探 Lambda Powertools TypeScript
Change exchange II - [leetcode]
SOFA Weekly | 年度优秀 Committer 、本周 Contributor、本周 QA
论坛系统数据库设计
Nacos Foundation (8): login management
激活函数之relu函数
随机推荐
ImportError: libX11.so.6: cannot open shared object file: No such file or directory
nacos基础(9):nacos配置管理之从单体架构到微服务
Maker education for primary and middle school students to learn in happiness
AcWing 1874. 哞加密(枚举,哈希)
Usage record of map < qstring, bool >
Redis optimization series (II) redis master-slave principle and master-slave common configuration
Significance of actively participating in middle school robot competition
力扣-70.爬楼梯
Study notes of C [8] SQL [1]
Understanding of MQ
解决由于找不到amd_ags_x64.dll,无法继续执行代码。重新安装程序可能会解决此问题,地平线(Forza Horizon 5)
Advanced file IO of system programming (13) -- IO multiplexing - Select
Tensorflow common functions
SOFA Weekly | 年度优秀 Committer 、本周 Contributor、本周 QA
Yunna | fixed assets inventory supports multiple inventory methods (asset inventory)
博客文章导航(实时更新)
IM表达式的目的(IM 5.2)
分享两个实用的shell脚本
解析社交性机器人对基础科学的作用
Nacos Foundation (8): login management