70. 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?

此题为典型的菲波那切数列问题;

当n=1时,有1种走法;

当n=2时,有2种走法;

当n=3时,有3种走法;

当n=4时,有5种走法;

......

当n=k时,有你n[k-1] + n[k-2]种走法;

代码如下:

 class Solution {
public:
int climbStairs(int n) {
if(n == )
{
return ;
}
if(n == )
{
return ;
}
int a = ;
int b = ;
int c;
for(int i = ; i < n; i++)
{
c = a + b;
a = b;
b = c;
}
return c;
}
};

最新文章

  1. jQuery 一句代码返回顶部
  2. rsync+inotify实现远程数据备份
  3. Android自定义Dialog及其布局
  4. [入门]bower安装和使用
  5. [网络配置相关]——ifconfig命令、ip命令、route命令
  6. [工作积累] error: bad class file magic (cafebabe) or version (0033.0000)
  7. 笨办法学C 练习
  8. zepto源码研究 - zepto.js-3 (常用的工具)
  9. HDU_2057——64位无符号16进制数的运算
  10. Python 第七篇:socket编程
  11. SWT实践过程中遇到的问题
  12. 解决ubuntu更新中断后报错问题
  13. python开发部署时新增数据库中表的方法
  14. IT轮子系列(三)——如何显示方法名——Swagger的使用(三)
  15. JS判断页面加载是否完成
  16. python接口自动化(十)--post请求四种传送正文方式(详解)
  17. Java锁与CAS
  18. 如何安装使用FastReport
  19. SVM中径向基函数与高斯核的区别 Difference between RBF and Gaussian kernel in SVM
  20. SpringBoot-服务端参数验证-JSR-303验证框架

热门文章

  1. ajax实现的无刷新分页代码实例
  2. SVN---脱离SVN控制
  3. WCF Windows Service Using TopShelf and ServiceModelEx z
  4. [原创博文] 用Python做统计分析 (Scipy.stats的文档)
  5. solr学习之添加文档
  6. C# BackgroundWorker的使用【转-http://www.cnblogs.com/tom-tong/archive/2012/02/22/2363965.html】
  7. PS 查看选定图层的高宽
  8. [SQL] 不知道是什么存储过程
  9. ListView之setEmptyView的问题
  10. 启用 CORS 来解决这个问题(ajax跨域请求)