[勇者闯LeetCode] 70. Climbing Stairs
[勇者闯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相关推荐
- 【斐波那切数列】LeetCode 70. Climbing Stairs
LeetCode 70. Climbing Stairs 这是一道利用斐波那切数列求解的题目.求斐波那切数列有比较经典的4种方法 (1)递归法:复杂度太高 (2)迭代法:时间复杂度为O(n)O(n)O ...
- [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 ...
- [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 ...
- 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 ...
- LeetCode#70 Climbing Stairs
Problem Definition: You are climbing a stair case. It takes n steps to reach to the top. Each time y ...
- leetcode: 70. Climbing Stairs
Problem # You are climbing a stair case. It takes n steps to reach to the top. # # Each time you can ...
- 70. Climbing Stairs
70. Climbing Stairs 1. 题目 You are climbing a stair case. It takes n steps to reach to the top. Each ...
- [勇者闯LeetCode] 1. Two Sum
[勇者闯LeetCode] 1. Two Sum Description Given an array of integers, return indices of the two numbers s ...
- [勇者闯LeetCode] 6. ZigZag Conversion
[勇者闯LeetCode] 6. ZigZag Conversion Description The string "PAYPALISHIRING" is written in a ...
最新文章
- DOM对象和JQUERY对象
- PyQt4 Python GUI窗体应用程序
- java-Calendar类
- Github 本周最热的 10 款「机器学习」开源项目 | PaperDaily #27
- 【Linux系统编程应用】 Linux Input子系统(一)
- 分布式锁概念与实现方案
- Android的硬件缩放技术优化执行效率 Screen.SetResolution
- FFmpeg 转码压缩
- 【产品】业务流程+任务流程+页面流程绘制指南
- 苹果xsmax有高通基带吗_苹果iPhone 12拆解:确认采用高通骁龙X55基带芯片
- 最短路默写1最短路默写2
- 清华数据女神评选结果:第一竟然是叉院大神...?
- Android源代码编译原理与前期准备
- DBA平均月薪17000,入职3年感叹这份工作实在是太难了!
- ChatGPT API调用python和脚本实现
- erlang 编译安装
- 基于51单片机的无线智能家居设计
- 1814. 所有子数组之和
- 越客连锁会员管理系统-会员管理轻松搞定
- 关于那些我们都听过的营销工具—优惠券