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. 重启猫(modem)的方法

    重启猫(modem)的方法 家里上网还是古老的"猫+路由器"模式,换路由器后就要reset猫,其步骤为: 断开猫电源 用针头或笔尖按住reset小孔,持续30秒 针抵住小孔的同时连 ...

  2. hdu 1166 敌兵布阵--BIT

    BIT模版题,学完直接刷毫无压力,水的不要不要的 敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  3. 从ICLassFactory 为 CLSID的COM组建创建实例失败:c001f011

    在sqlserver创建计划任务的时候,保存时出现:“从ICLassFactory 为 CLSID的COM组建创建实例失败:c001f011”. 解决方法:在运行sqlserver时,使用“以管理员身 ...

  4. 洛谷P1736 创意吃鱼法

    题目描述 回到家中的猫猫把三桶鱼全部转移到了她那长方形大池子中,然后开始思考:到底要以何种方法吃鱼呢(猫猫就是这么可爱,吃鱼也要想好吃法 ^_*).她发现,把大池子视为01矩阵(0表示对应位置无鱼,1 ...

  5. Linux文件权限;ACL;Setuid、Setgid、Stick bit特殊权限;sudo提权

    相关学习资料 http://blog.sina.com.cn/s/blog_4e2e6d6a0100g47o.html http://blog.csdn.net/aegoose/article/det ...

  6. iOS开发的那些坑

    最近重新拿起了iOS的开发,使用OC和Swift混编,碰到了一些比较棘手的问题,在这里记录下来,方便自己以后或他人不再入坑.这篇文章的内容包含: UITableViewCell的真实结构在iOS的环境 ...

  7. easyui之datagrid的使用

    http://www.cnblogs.com/ruanmou001/p/3840954.html 一.神马是easyui jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery ...

  8. Fast-cgi cgi nginx php-fpm 的关系 (转

    Fast-cgi  cgi  nginx  PHP-fpm 的关系 Fast-cgi是由cgi发展而来,是http服务器(http,nginx等)和动态脚本语言(php,perl等)之间的的通信接口, ...

  9. Deep Learning in a Nutshell: Core Concepts

    Deep Learning in a Nutshell: Core Concepts This post is the first in a series I’ll be writing for Pa ...

  10. mysql 一个典型的数据库建表建用户过程

    cmd 命令不接 ";" mysql 命令后接 ";" 1.以管理员身份登录mysql mysql -u root –p 2.选择mysql数据库 use my ...