Problem

# You are climbing a stair case. It takes n steps to reach to the top.
#
# Each time you can either climb 1 or 2 steps.
# In how many distinct ways can you climb to the top?
#
# Note: Given n will be a positive integer.

AC

DP (动态规划):

class Solution():def climbStairs(self, n):pre, cur = 0, 1for _ in range(n):pre, cur = cur, pre + curreturn cur

递归,会 Time Limit Exceeded (超时):

# Time Limit Exceeded
class Solution():def climbStairs(self, n):if n == 1:return 1if n == 2:return 2return self.climbStairs(n - 1) + self.climbStairs(n - 2)if __name__ == "__main__":assert Solution().climbStairs(2) == 2

leetcode: 70. Climbing Stairs相关推荐

  1. 【斐波那切数列】LeetCode 70. Climbing Stairs

    LeetCode 70. Climbing Stairs 这是一道利用斐波那切数列求解的题目.求斐波那切数列有比较经典的4种方法 (1)递归法:复杂度太高 (2)迭代法:时间复杂度为O(n)O(n)O ...

  2. [勇者闯LeetCode] 70. Climbing Stairs

    [勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...

  3. [LeetCode]70.Climbing Stairs

    [题目] You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...

  4. [leetcode 70]Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  5. LeetCode 70. Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  6. LeetCode#70 Climbing Stairs

    Problem Definition: You are climbing a stair case. It takes n steps to reach to the top. Each time y ...

  7. 70. Climbing Stairs

    70. Climbing Stairs 1. 题目 You are climbing a stair case. It takes n steps to reach to the top. Each ...

  8. leetcode python3 简单题70. Climbing Stairs

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第七十题 (1)题目 英文: You are climbing a stair ca ...

  9. 【LeetCode】70 - Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

最新文章

  1. 易语言读写配置项ini文件
  2. proxy error: could not proxy request解决方案
  3. 背景图片生成网站收集
  4. 【nginx】【小记】泛解析大量域名的情况下 将不带www的域名,301到与之对应的www前缀的域名
  5. favicon.ico是什么?
  6. java concurrent 框架_Java Concurrent 框架图
  7. Criteo公司在上海新开通一个数据中心
  8. 浏览器对象模型(Browser Object Model)
  9. SVN配置–服务器端(linux)
  10. MultiDesk远程桌面连接
  11. 项目管理之敏捷开发之道
  12. uniapp实现公众号H5、小程序和App微信授权登录功能
  13. 入选数据库顶会 VLDB:如何有效降低产品级内存数据库快照尾延迟?
  14. linux中用zip压缩文件,详解Linux中zip压缩和unzip解压缩命令及使用详解
  15. 用Python编写的五子棋程序1.0版
  16. 史上最完美的 Typora 教程
  17. 动态规划--数位dp--二进制状态压缩
  18. 注意力机制工作原理详解
  19. 是否能构成三角形java
  20. 笔记本开机后桌面图标变乱

热门文章

  1. 刚刚下载的eclipse打不开?一点击就报错
  2. 详解train_test_split()函数(官方文档有点不说人话)
  3. 如何实现 Oracle 的自增序列,两步轻松搞定
  4. 微信公众平台接口测试帐号申请流程
  5. 浏览器使用默认端口9006连接TinyWebServer服务器连接不上?
  6. 企业越小越需要做股权激励
  7. 2019C语言课程设计
  8. c语言字母存储,字符串在内存中的储存——C语言进阶
  9. PySide2与PyQt5区别
  10. 生成静态链接库和动态链接库