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;
}
};

leetcode 70的更多相关文章

  1. [LeetCode] 70. Climbing Stairs 爬楼梯问题

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  2. LeetCode 70. 爬楼梯(Climbing Stairs)

    70. 爬楼梯 70. Climbing Stairs 题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意: 给定 ...

  3. 42. leetcode 70. Climbing Stairs

    70. Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time y ...

  4. Leetcode#70. Climbing Stairs(爬楼梯)

    题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解 ...

  5. LeetCode 70 Climbing Stairs(爬楼梯)(动态规划)(*)

    翻译 你正在爬一个楼梯. 它须要n步才干究竟顶部. 每次你能够爬1步或者2两步. 那么你有多少种不同的方法爬到顶部呢? 原文 You are climbing a stair case. It tak ...

  6. 算法题之Climbing Stairs(leetcode 70)

    题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...

  7. LeetCode(70)题解: climbing-stairs

    https://leetcode.com/problems/climbing-stairs/ 题目: You are climbing a stair case. It takes n steps t ...

  8. LN : leetcode 70 Climbing Stairs

    lc 70 Climbing Stairs 70 Climbing Stairs You are climbing a stair case. It takes n steps to reach to ...

  9. [LeetCode] 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. transform.localPosition操作时的一些注意事项

    移动GameObject是非常平常的一件事情,一下代码看起来很简单: transform.localPosition += new Vector3 ( 10.0f * Time.deltaTime, ...

  2. 图片--Android加载图片导致内存溢出(Out of Memory异常)

    Android在加载大背景图或者大量图片时,经常导致内存溢出(Out of Memory  Error),本文根据我处理这些问题的经历及其它开发者的经验,整理解决方案如下(部分代码及文字出处无法考证) ...

  3. 外中断之swi软件中断:

    在stm32的标准库的外中断库文件中有void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line);原来一直不知道有什么用,现总结一下: 作用:软件模拟产生中断能 ...

  4. 基于NPOI的Execl导入导出例子

    源地址:http://bbs.csdn.net/topics/390830774

  5. 一步步教你如何把电脑设置U盘启动(图解教程)

    一.我们先来说说如何进入 BIOS设置程序: 在开机时按下特定的热键可以进入BIOS设置程序,不同类型的机器进入BIOS设置程序的按键不同,有的在屏幕上给出提示,有的不给出提示,几种常见的BIOS设置 ...

  6. struts2中action中的通配符

    struts中一个正常的最普通不过的action是这样子的 <package name="default1" namespace="/gys" exten ...

  7. ckfinder的配置使用

    1.单纯的上传图片和预览图片 修改configasp中CheckAuthentication = true; 否则的话会报没有权限或修改配置错误 此时如果可以查看的话,单击图片应该是放大并且预览图片 ...

  8. SPCOMM 接收数据不完整!该如何解决

    SPCOMM 接收数据不完整!该如何解决   SPCOMM 接收数据不完整!我作了一个 读取地磅数据的程序,是用spcomm接收的! 总共有五台地磅,其他4台地磅数据读取都正常.但是有一台接收数据的时 ...

  9. 立体匹配:关于OpenCV读写middlebury网站的给定的视差并恢复三维场景的代码

    Middlebury是每个研究立体匹配算法的人不可能不使用的网站,Middlebury提供了许多标准的测试库,这极大地推进了立体匹配算法的进展.Middlebury提供的标准库,其计算出的视差保存在后 ...

  10. lower_bound 和 upper_bound

    Return iterator to lower bound Returns an iterator pointing to the first element in the range [first ...