Climbing Stairs
来源:互联网 发布:公司seo是什么职位 编辑:程序博客网 时间:2024/06/06 15:00
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?
Note: Given n will be a positive integer.
class Solution {
public:
int climbStairs(int n) {
if(n <= 0) return 0;
if(n == 1) return 1;
if(n == 2) return 2;
int one_step_before = 2;
int two_steps_before = 1;
int all_ways = 0;
for(int i=2; i<n; i++){
all_ways = one_step_before + two_steps_before;
two_steps_before = one_step_before;
one_step_before = all_ways;
}
return all_ways;
}
};
0 0
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- SSH--Hibernate传值为乱码 || 显示为乱码
- 避免把情绪带进工作
- idea 新增lombok插件
- MyEclipse关联源码
- C程序设计语言第二版1.21
- Climbing Stairs
- ubuntu 16.04 virtualbox could not insert 'vboxdrv': Required key not available 问题解决方法
- 记录-Bootstrap编写个人网站主页
- AlarmManager
- redis的数据类型-List
- YiqiangXu的博客 - CSDN博客
- 移动端适配方案总结
- TensorFlow实现Titanic比赛
- Java多线程中的内存模型