当前位置:网站首页>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
边栏推荐
- Redis learning 5 - high concurrency distributed lock practice
- Compress the curl library into a sending string of utf8 and send it with curl library
- thinkphp 添加图片文字水印生成带二维码的推广海报
- 5个免费音频素材网站,建议收藏
- Database design of simple voting system
- Summary of QT semaphore unresolved errors
- Interpretation of 2022 robot education industry analysis report
- Castle.DynamicProxy实现事务单元控制
- 一文详解头部位姿估计【收藏好文】
- Golang Pen & interview 01
猜你喜欢
云呐|如何管理好公司的固定资产,固定资产管理怎么做
解读2022机器人教育产业分析报告
rebbitMQ的简单搭建
激活函数之relu函数
激活函数之sigmoid函数
Use kettle to copy records to and get records from results
Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
The way to change children's programming structure
Practical data Lake iceberg lesson 30 MySQL - > iceberg, time zone problems of different clients
激活函数之阶跃函数
随机推荐
分享两个实用的shell脚本
Laravel增加自定义助手函数
解读机器人创造出来的艺术
少儿编程结构的改变之路
1.Electron开发环境搭建
My creation anniversary
thinkphp 添加图片文字水印生成带二维码的推广海报
Nacos Foundation (9): Nacos configuration management from single architecture to microservices
The fourth chapter is to enable the filling object of IM and enable ADO for im column storage (IM 4.8)
redis优化系列(二)Redis主从原理、主从常用配置
MQ的了解
解析幼儿教育中steam教育的融合
Pytorch neural network trainer
nacos基础(9):nacos配置管理之从单体架构到微服务
2022 love analysis · panoramic report of industrial Internet manufacturers
Redis学习之五---高并发分布式锁实战
Maker education for primary and middle school students to learn in happiness
Study notes of C [8] SQL [1]
Cognition and R & D technology of micro robot
Change exchange II - [leetcode]