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. 使用SVN进行项目版本管理

    1.摘要 本文描述了利用SVN进行项目版本管理的方法,涉及项目版本号命名规则.SVN目录结构.第三方代码库的管理.版本创建.发布.修订.合并等行为的方法和原则. 2.版本号命名规则 版本号采用主版本号 ...

  2. gcc makefile

    $* 不包含扩展名的目标文件名称 $< 第一个依赖文件名称 $? 所有时间戳比目标文件晚的依赖文件 $@ 目标文件完整名称 $^ 所有不重复的依赖文件

  3. grep和sed替换文件中的字符串

    sed -i s/"str1"/"str2"/g `grep "str1" -rl --include="*.[ch]" ...

  4. [Java] 02 String的常用方法

    public class TestString{ public static void main(String[] args){ String str1 = "123"; Stri ...

  5. crm 4 注释与上传附件权限

    文档注释权限及上传附件是与实体的”追加到”权限有关. 文档注释权限及上传附件是与核心记录中”注释”的”追加”权限有关. 追加及追加到的权限,我的理解是与本实体有关联的实体的权限,比如你引用了其它表的字 ...

  6. TestNG运作报错An interanl error occurred during:"Launching first"

    备注:我建的类名就叫做“first” 解决办法:卸载掉TestNG M2E Help-->Install new software-->What is already installed? ...

  7. 日志挖掘Logmnr

    日志挖掘 9.1 日志中数据用途 所有对用户数据以及数据字典的改变全部被保存在联机日志中.当然nologging,insert/*+append+/情况比较特殊除外,因此归档日志可以用来做数据库的恢复 ...

  8. getdata

    public partial class GetData : System.Web.UI.Page { protected void Page_Load(object sender, EventArg ...

  9. WIN7上搭建Windows Phone 8 开发环境——VMware Workstation下Win8 “无法安装Hyper-V, 某个虚拟机监控程序正在运行”问题解决的办法

    最近在试着在Windows 7上搭建Windows Phone 8的开发调试环境,使用的是VMware Workstation + Win8 Pro的虚拟环境, 在漫长的WPexpress_full下 ...

  10. Java: 基类、子类、构造函数、程序块的初始化顺序

    初始化顺序 基类static block 子类static block 基类non-static block 子类non-static block 基类constructor 子类constructo ...