[勇者闯LeetCode] 70. Climbing Stairs

Description

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.

Information

  • Tags: Dynamic Programming
  • Difficulty: Easy

Solution

实质上是Fibonacci Number:
Fib(n)=Fib(n−1)+Fib(n−2),Fib(1)=1,Fib(2)=2 Fib(n)=Fib(n−1)+Fib(n−2), Fib(1)=1, Fib(2)=2,
即爬到n阶的方法数等于爬到n-1阶的方法数和爬到n-2阶的方法数之和,爬到1阶的方法数是1,爬到2阶的方法数是2。

class Solution(object):def climbStairs(self, n):""":type n: int:rtype: int"""prev, cur = 0, 1for i in range(n):prev, cur = cur, cur + prevreturn cur

[勇者闯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

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

  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 climb ...

  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

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

  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] 1. Two Sum

    [勇者闯LeetCode] 1. Two Sum Description Given an array of integers, return indices of the two numbers s ...

  9. [勇者闯LeetCode] 6. ZigZag Conversion

    [勇者闯LeetCode] 6. ZigZag Conversion Description The string "PAYPALISHIRING" is written in a ...

最新文章

  1. DOM对象和JQUERY对象
  2. PyQt4 Python GUI窗体应用程序
  3. java-Calendar类
  4. Github 本周最热的 10 款「机器学习」开源项目 | PaperDaily #27
  5. 【Linux系统编程应用】 Linux Input子系统(一)
  6. 分布式锁概念与实现方案
  7. Android的硬件缩放技术优化执行效率 Screen.SetResolution
  8. FFmpeg 转码压缩
  9. 【产品】业务流程+任务流程+页面流程绘制指南
  10. 苹果xsmax有高通基带吗_苹果iPhone 12拆解:确认采用高通骁龙X55基带芯片
  11. 最短路默写1最短路默写2
  12. 清华数据女神评选结果:第一竟然是叉院大神...?
  13. Android源代码编译原理与前期准备
  14. DBA平均月薪17000,入职3年感叹这份工作实在是太难了!
  15. ChatGPT API调用python和脚本实现
  16. erlang 编译安装
  17. 基于51单片机的无线智能家居设计
  18. 1814. 所有子数组之和
  19. 越客连锁会员管理系统-会员管理轻松搞定
  20. 关于那些我们都听过的营销工具—优惠券

热门文章

  1. Oracle授权语句
  2. iOS数据库框架 WCDB的使用详解
  3. VINS_MONO系列:(五)前端特征提取
  4. Echarts常用属性---附智能看板素材
  5. LSTM前向传播与反向传播算法推导(非常详细)
  6. 2020年Github项目排行Top20项目
  7. 数据交互工具 -- HUE
  8. 用精灵图拼出自己的名字
  9. cmd命令基础知识学习笔记
  10. Excel中使用宏工具,告别重复工作,批量处理xls文件 - WPS Excel