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. 【HDU 2577】How to Type

    题意 (我做了这题才知道caps lock 锁定大小写后,按一下shift键可以输入相反的大小写.) 这题就是给你只有大小写字母的字符串,求最少多少次按键盘.最后caps lock 必须是关闭的. 分 ...

  2. 学习笔记 BIT(树状数组)

    痛定思痛,打算切割数据结构,于是乎直接一发BIT 树状数组能做的题目,线段树都可以解决 反之则不能,不过树状数组优势在于编码简单和速度更快 首先了解下树状数组: 树状数组是一种操作和修改时间复杂度都是 ...

  3. PHP 数据库驱动、连接数据不同方式学习笔记

    相关学习资料 http://www.php.net/manual/zh/refs.database.php http://www.php.net/manual/zh/internals2.pdo.ph ...

  4. MS-sqlserver数据库2008如何转换成2000

    http://bbs.csdn.net/topics/390438560?page=1#post-394316973 MS-sqlserver数据库2008如何转换成2000 回你这个贴等于我写个博客 ...

  5. mongo(删除操作)

    在使用MongoDB的时候,经常会用到MongoDB的删除操作,以下是我在使用MongoDB删除操作的总结 首先是删除用户: db.removeUser("用户名") 其次是删除数 ...

  6. iOS项目工作空间搭建

    一般公司的项目都是一个工作空间包包含两个项目,一个主项目,一个Pods项目,当然也有些就是一个项目,然后把第三方放在项目的文件夹里. 这样做的好处是,项目再次拷贝到其他地方报错的可能性小,而且拷完就能 ...

  7. dao、domain、service、web、vo、Model这些层的功能是什么

    这些层次都是用来管理不同的代码,让代码具有更好的维护性.开发中一般采用三层架构即MVC的模式来进行开发,M:代表model,可以理解为javaBean:V:代表view,可以理解为jsp:c:代表co ...

  8. SQL中CONVERT转化函数的用法

    格式:CONVERT(data_type,expression[,style])说明:此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,c ...

  9. Linux下远程cp命令scp

    2014-2.19  PS1.在用此命令cpLinux与Linux之间的数据时发现有些服务器上默认没有安装scp但用yum -y install scp提示么有这样的包 后来发现原来scp工具的安装包 ...

  10. 将DataTable导出为Excel C#

    /// <summary> /// 导出Excel /// </summary> /// <param name="dt">DataTable& ...