<LeetCode><Easy> 70 Climbing Stairs #斐波那契数列
来源:互联网 发布:c stl 源码解析 pdf 编辑:程序博客网 时间:2024/04/30 02:46
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?
#Python2 TimeOut 递归 是斐波那契数列
class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int """ return self.climbStairs(n-1)+self.climbStairs(n-2) if n>2 else 2 if n>1 else 1
#Python2 循环方式 88ms
class Solution(object): def climbStairs(self, k): """ :type n: int :rtype: int """ if not k-1:return 1 i=2 fs=[1,2] while i<k: fs.append(fs[-2]+fs[-1]) i+=1 return fs[-1]
#Python2 优化循环 36ms
class Solution(object): def climbStairs(self, k): """ :type n: int :rtype: int """ if k<3:return 1 if k-1==0 else 2 s0,s1=1,2 for i in range(2,k): s1,s0=s0+s1,s1 return s1
1 0
- <LeetCode><Easy> 70 Climbing Stairs #斐波那契数列
- LeetCode-70 Climbing Stairs(斐波那契数列)
- 70.leetcode Climbing Stairs(easy)[递推表示式 斐波那契数列]
- [LeetCode] 70. Climbing Stairs(斐波那契数列)
- leetcode笔记:Climbing Stairs(斐波那契数列问题)
- LeetCode之Climbing Stairs与斐波那契数列的联想
- [LeetCode]70. Climbing Stairs 斐波那契数列&&动态规划
- leetcode70-Climbing Stairs(斐波那契数列)
- 70. Climbing Stairs -- 动态规划、斐波那契数列
- [Leetcode 70, easy] Climbing Stairs
- 【LeetCode】(70)Climbing Stairs (Easy)
- Leetcode #70 - Climbing Stairs - Easy
- 【Leetcode-Easy-70】Climbing Stairs
- 【70 Climbing Stairs】菲波那切数列解决思路
- LeetCode-70-Climbing Stairs(动态规划)-Easy
- Leetcode OJ 70 Climbing Stairs [Easy]
- [leetcode][easy]70. Climbing Stairs
- (Leetcode)70.Climbing Stairs(easy)
- ubuntu14.04 源码安装Qt 5.4
- Android Studio平台使用GreenDao操作数据库
- Spark standalone模式安装
- HDU-2845-Beans-简单dp
- CoreData的版本迭代
- <LeetCode><Easy> 70 Climbing Stairs #斐波那契数列
- javaweb学习路线
- Mac打开终端的方法
- (一)蚂蚁是否能到另一端
- 缓存
- 值得学习的C语言开源项目
- Swift学习遇到的问题
- ios-屏幕适配masonry的使用
- 使用DatePicker和TimePicker实现日历功能