Problem Definition:

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?

Solution: 可以用动态规划来解。令爬n级阶梯的方式有f(n)种。

  要到达第n级阶梯,要么是从第n-1级阶梯爬一步,要么是从第n-2级阶梯爬两步(一次性)。而这两种情况是没有交集的。

  因此得到:f(n)=f(n-1)+f(n-2)  (当n>1)

  oops...正是斐波那契数列。

1 def climbStairs(n):
2     a,b,i=[1]*3
3     while i<n:
4         a,b=b,a+b
5         i+=1
6     return b

转载于:https://www.cnblogs.com/acetseng/p/4671469.html

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 # You are climbing a stair case. It takes n steps to reach to the top. # # Each time you can ...

  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. python代码创建数据库_如何使用python ORM创建数据库表?
  2. 讨论:如何降低Cocos2d开发的游戏包体大小
  3. 判断一个对象是否存在某个键_面向工业大数据的对象存储技术实践
  4. 情感分析(Sentiment Analysis)的难题--转
  5. mysql update 行迁移_Oracle行迁移和行链接详解
  6. lost connection to MySQL server at waiting for initial communication packet,system error:o
  7. C语言中sizeof和strlen的区别是什么
  8. might和could的区别用法_might 与 could区别,谢谢,may和might的区别及用法
  9. 浅谈人工智能:现状、任务、构架与统一 | 正本清源(看完有新认知)
  10. 看图识WAF-搜集常见WAF拦截页面
  11. 你学习·我奖励,21天学习挑战赛 | 等你来战
  12. Elasticsearch嵌套式对象Nested分析
  13. 静态路由,缺省路由和默认网关的区别
  14. 关于男女交往的换位思考
  15. 【密码学】费马小定理素性检测(C++代码实现)
  16. 相机标定——张正友棋盘格标定法
  17. KODI 电视版本以及字母插件的安装
  18. 桌面计算机没反应是什么意思,点击显示桌面没反应? 显示桌面没反应解决方法...
  19. STM32(C语言)内存分布
  20. 计算机运算和控制核心的简称,计算机的核心是什么

热门文章

  1. java 不存在数据返回的值是什么_Java方法
  2. tensorflow对应的numpy版本_版本更新 | TensorFlow 2.4.0 候选版本发布
  3. JS - 将十六进制的颜色值转成rgb、rgba格式
  4. java性能测试jmh
  5. java输出动物,求大神帮助输出为什么只有动物名,几条腿,怎么叫,没有汤姆猫叫等...
  6. java设计模式懒汉_JAVA设计模式之懒汉式
  7. 火绒弹窗拦截_弹窗广告的克星:火绒安全软件图文使用教程
  8. php mysql 非空_PHP-为什么mysql接受非空字段为null
  9. 虚拟机如何配置网络ip地址_木杉入门Elasticsearch(2):虚拟机IP地址配置
  10. java里面super(),Java中super