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?

解题思路:

递归会导致超时,用动态规划即可,JAVA实现如下;

    public int climbStairs(int n) {
if(n==1)
return 1;
else if(n==2)
return 2;
int[] v=new int[n];
v[0]=1;
v[1]=2;
for(int i=2;i<v.length;i++)
v[i]=v[i-1]+v[i-2];
return v[n-1];
}

Java for LeetCode 070 Climbing Stairs的更多相关文章

  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 爬楼梯

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

  3. leetCode 70.Climbing Stairs (爬楼梯) 解题思路和方法

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

  4. 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 ...

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

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

  6. 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 ...

  7. Java [Leetcode 70]Climbing Stairs

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

  8. 【LeetCode】070. Climbing Stairs

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

  9. [LeetCode OJ]-Climbing Stairs

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

随机推荐

  1. 细菌觅食算法-python实现

    BFOIndividual.py import numpy as np import ObjFunction class BFOIndividual: ''' individual of bateri ...

  2. BZOJ-2257 瓶子和燃料 分解因数+数论方面乱搞(裴蜀定理)

    一开始真没想出解法...后来发现那么水.... 2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 970 So ...

  3. c++ 函数调用在进入下一个循环的时候会再次初始化参数,将函数体直接写进去就正常

    #include"stdafx.h" #include"string" #include<iostream> #include<vector& ...

  4. 在.NET使用JSON作为数据交换格式

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://zhoufoxcn.blog.51cto.com/792419/517093 我们 ...

  5. Memcache和Redis

  6. win10系统安装.net35的命令行方式

    有些程序在windows系统中需要安装.net35才能运行,下载太慢了,可以直接在docs窗口直接安装,命令行如下:Dism /online /enable-feature /featurename: ...

  7. DedeCMS 5.7 后门漏洞

    简要描述: DedeCMS V5.7 SP1正式版 UTF-8 GBK版本疑似被植入一句话后门 前几日下载并不存在此代码 详细说明: shopcar.class.php被植入一句话@eval(file ...

  8. PHP定界符 heredoc

    <?php echo <<<EOT //如果这个后面有空格,报错... haha EOT; //如果这个后面有空格,报错[如果没有空格,就这样文件直接结束,同样报错,请在EOT ...

  9. js Float 精度

    1.加法 //加法 function add(arg1,arg2){ var r1,r2,m; try{r1=arg1.toString().split(".")[1].lengt ...

  10. ES+Hbase对接方案概述

    方案背景 Hbase的索引方案有很多,越来越多的人开始选择ES+Hbase的方案,其实该方案并没有想象中那么完美,ES并发低,同时查询速度相对Hbase也慢很多,那为什么会选择他呢,它的写入比较快,如 ...