leetcode-70. Climbing Stairs
2016-04-24 18:15
381 查看
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?
思路:就是斐波那契数列
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) { //就是斐波那契数列 if(n < 1) { return 0; } if(n == 1) { return 1; } if(n == 2) { return 2; } int stepPre = 1; int stepLater = 2; int result = 0; for(int i = 3;i<=n;i++) { result = stepPre + stepLater; stepPre = stepLater; stepLater = result; } return result; } };
相关文章推荐
- adv7180 驱动 设置ain 输入
- TensorFlow人工智能引擎入门教程之九 RNN/LSTM循环神经网络长短期记忆网络使用
- 稀疏编码(Sparse Coding)的前世今生(一) 转自http://blog.csdn.net/marvin521/article/details/8980853
- STL map的遍历与pair的使用
- 生产者消费者模型——wait/notify/notifyAll使用
- BNU 51640 Training Plan DP
- Airbase-ng帮助
- Capturing 'self' strongly in this block is likely to lead to a retain cycle
- Failure to transfer org.apache.maven.plugins:maven-war-plugin:pom:2.2 from https://repo.maven.apache
- init done opengl support available
- 172. Factorial Trailing Zeroes
- HDU 2389 Rain on your Parade (HK二分图)
- rt3070无线网卡工作在staion模式----fl2440开发板
- leetcode-217. Contains Duplicate
- 5、Jenkins Email Extension Plugin插件使用说明
- hdu3487Play with Chain【splay】
- 计算机视觉和人工智能领域:教程、网站、博客记录(陆续更新)
- spoj16935 Straight Line Spiral Pattern (Act 3)
- TIME_WAIT状态原理
- “人工智能大脑”跳槽记:吴恩达所理解的智能