【LeetCode】70. Climbing Stairs
2016-03-09 14:53
471 查看
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?
【思路】斐波那契数列,第n阶是由第n-1阶和n-2阶的方法求和而成。
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
【思路】斐波那契数列,第n阶是由第n-1阶和n-2阶的方法求和而成。
class Solution { public: int climbStairs(int n) { if(n<=2) return n; int f ={0}; f[0]=1; f[1]=2; for(int i =2; i < n;i++) { f[i] = f[i-1] + f[i-2]; } return f[n-1]; } };
相关文章推荐
- CodeForces 630A:Again Twenty Five!【水题】
- Codeforces 651B Beautiful Paintings【思维】
- 【Training Contest】2016.03.08
- hdu 1021Fibonacci Again
- WPF 从Main函数启动
- 提交git push 时failed to push some refs to
- 解决httpd: Could not reliably determine the server's fully qualified domain name
- Xcode提交图片出错:Commit failed not under version control (1)
- rails 限制上传图片大小出现 Errno::ENOENT in MicropostsController#create 错误
- 40页Pacific Trails Resort案例分析
- aix用命令查监听端口对应的进程
- BC31pairs&&hdoj5178&&hdoj5179
- HUST 1606 - Naive
- HUST 1606 - Naive
- 11. Container With Most Water
- 不了解一下人工智能的发展历史,又怎么能看明白 AlphaGo 的对战呢
- 多线程并发的解决方案 volatile synchronized notify notifyAll wait关键字分析
- AIR程序生成系统托盘
- Adobe AIR迷你教程 -- 使用自定义窗口以及对窗口的移动,缩放,关闭操作
- AIR2.0特性回顾