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层的方式(爬两层)的和

class Solution {
public:
int climbStairs(int n) {
if(n <= ) return ;
else if(n == ) return ;
else if(n == ) return ;
else
{
int way1 = ;
int way2 = ;
int ans = ;
for(int i = ; i <= n; i++)
{
ans = way1 + way2;
way2 = way1;
way1 = ans;
}
return ans;
}
}
};

最新文章

  1. Easyui datagrid行内【添加】、【编辑】、【上移】、【下移】
  2. 数据库 CRUD
  3. 使用MSBUILD 构建时出错 error MSB3086: Task could not find &quot;sgen.exe&quot; using the SdkToolsPath的解决方法
  4. [转]GLES 3.0 新特性
  5. bzoj1485:[HNOI2009]有趣的数列
  6. Preferred Java way to ping a HTTP Url for availability
  7. jdom学习:读取xml文件
  8. zookeeper 各节点数据保证是弱一致性
  9. Fixjs实践——标签、按钮控件
  10. Android 6.0动态添加权限
  11. CentOS 7 时区设置
  12. Shell常见用法小记
  13. MicrosoftWebInfrastructure 之坑
  14. How to configure Samba Server share on Debian 9 Stretch Linux
  15. poj3067 二维偏序树状数组
  16. 利用Python 脚本生成 .h5 文件 代码
  17. mybatis一(常用配置信息和获取插入后id)
  18. ES6简介之let和const命令解说
  19. 【Devops】【docker】【CI/CD】2.docker启动jenkins环境+安装必要的插件
  20. Python之CMDB资产管理系统

热门文章

  1. PHP支付宝接口RSA验证
  2. PHP输出缓冲(Output Buffering)
  3. [译]Mongoose指南 - Population
  4. 【转】GATK使用方法详解(包含bwa使用)
  5. Android在TextView中实现RichText风格
  6. 我们为之奋斗过的C#-----C#的一个简单理解
  7. python 输入和输出
  8. CSS3-transform,2D动画实例
  9. [转载]JavaEE学习篇之——网络传输数据中的密码学知识以及Tomcat中配置数字证书EE
  10. Caffe学习系列(16):caffe的整体流程