LeetCode OJ:Climbing Stairs
来源:互联网 发布:学校网络机房设计方案 编辑:程序博客网 时间:2024/05/22 08:01
Climbing Stairs
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?
class Solution {public: int climbStairs(int n) { int a=1,b=1,t; for(int i=2;i<=n;i++){ t=a; a=a+b; b=t; } return a; }};
answer2
数学公式,斐波那契数列通项:
n
n
n
F
2
5
1
2
5
1
5
1
class Solution {public: int climbStairs(int n) { const double s=sqrt(5); double a=(1+s)/2; double b=(1-s)/2; return floor((pow(a,n+1)+pow(b,n+1))/s+0.5); }};
n
n
n
F
2
5
1
2
5
1
5
1
n
n
n
F
2
5
1
2
5
1
5
1
0 0
- LeetCode OJ:Climbing Stairs
- LeetCode OJ - Climbing Stairs
- [LeetCode OJ]Climbing Stairs
- LeetCode OJ Climbing Stairs
- <LeetCode OJ> 70. Climbing Stairs
- [leetcode oj 70]Climbing Stairs
- LeetCode OJ 之 Climbing Stairs ( 爬楼梯 )
- Leetcode OJ 70 Climbing Stairs [Easy]
- LeetCode OJ算法题(七十):Climbing Stairs
- LeetCode OJ-70. Climbing Stairs(爬楼梯问题)
- LeetCode: Climbing Stairs
- LeetCode: Climbing Stairs
- [LeetCode]Climbing Stairs
- LeetCode Climbing Stairs
- [Leetcode] Climbing Stairs
- Leetcode: Climbing stairs
- LeetCode Climbing Stairs
- [LeetCode] Climbing Stairs
- java环境变量配置
- NAT与NAT穿透
- Photography Masterclass
- Android 程序图标需要的尺寸
- zeromq 学习
- LeetCode OJ:Climbing Stairs
- Hibernate properties详解
- 语音有杂音
- SDP 协议分析
- C#之virtual 和abstract
- 转 VAGE的探索频道:Oracle时间之旅
- webform间传参的3种常用方式
- 版本管理
- DBCP、C3P0、Proxool 、 BoneCP开源连接池的比较