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. Javascript函数声明与函数表达式

    在定义函数时,我们一般使用下面这两种方法: 使用函数声明定义: function sum (a, b) { return a + b; } 使用函数表达式定义: var sum = function ...

  2. RVMDK的DEBUG调试-实时数据查看

    无论在Simulation还是硬件仿真的情况下,View-period windows update后watch窗口添加的变量即可实时更新, 软仿真和硬件仿真的区别就是实际时间的差异:如RTC查看秒的 ...

  3. 常见数组&字符串API及其应用场景总结

    数组API: String(arr):将arr中每个元素转化为字符串,逗号连接     场景:用于鉴别数据有没有修改等. ps:String是万能的   toString 只能转换除null和unde ...

  4. Bootstrap学习的点点滴滴

    1)网站:http://www.bootcss.com/http://v3.bootcss.com/getting-started/#downloadhttps://github.com/twbs/b ...

  5. windowns--HANDLE,

    HANDLE: 在windows程序中,有各种各样的资源(窗口.图标.光标等),系统在创建这些资源时会为他们分配内存,并返回标示这些资源的标示号,即句柄. 句柄指的是一个核心对象在某一个进程中的唯一索 ...

  6. 查看mysql数据库引擎

    1.查看支持的引擎 show engines; 2.查看当前引擎 show variables like '%storage_engine%'

  7. [ActionScript 3.0] AS3 深入理解Flash的 应用程序域Application Domains

    简介 网上有很多flash,通常都不需要显示的使用应用程序域,因为默认的应用程序域就够用了.其实复杂的情况下需要用到应用程序域,比如说有两个不同的swf,一个是旧版本的,一个是新版的,这两个文件里的类 ...

  8. SQLSERVER:计算数据库中各个表的数据量和每行记录所占用空间

    转:http://www.cnblogs.com/lyhabc/p/3828496.html CREATE TABLE #tablespaceinfo ( nameinfo ) , rowsinfo ...

  9. 2013 ACM 通化邀请赛 A. Tutor

    A. Tutor Description Lilin was a student of Tonghua Normal University. She is studying at University ...

  10. BC-Clarke and five-pointed star(水)

    Clarke and five-pointed star Accepts: 237 Submissions: 591 Time Limit: 2000/1000 MS (Java/Others) Me ...