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?

Subscribe to see which companies asked this question

简单的dp问题,代码如下:

 class Solution {
public:
int climbStairs(int n) {
if(n <= )
return n;
dp.resize(n + );
dp[] = ;
dp[] = ;
for(int i = ; i < n + ; ++i){
dp[i] += dp[i - ];
dp[i] += dp[i - ];
}
return dp[n];
}
private:
vector<int> dp;
};

java版本代码如下所示:

 public class Solution {
public int climbStairs(int n) {
if(n < ) return n;
int dp [] = new int [n+];
dp[] = ;
dp[] = ;
for(int i = ; i <= n; ++i){
dp[i] = dp[i-] + dp[i-];
}
return dp[n];
}
}

LeetCode OJ:Climbing Stairs(攀爬台阶)的更多相关文章

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

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

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

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

  3. [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 ...

  4. LeetCode 70 Climbing Stairs(爬楼梯)(动态规划)(*)

    翻译 你正在爬一个楼梯. 它须要n步才干究竟顶部. 每次你能够爬1步或者2两步. 那么你有多少种不同的方法爬到顶部呢? 原文 You are climbing a stair case. It tak ...

  5. LeetCode OJ——Climbing Stairs

    http://oj.leetcode.com/problems/climbing-stairs/ 走台阶的题目,转换出数学模型之后,就是Fibonacci数列.后一个数等于前两个数的和. 递归版本超时 ...

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

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

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

  9. LeetCode746 Min Cost Climbing Stairs(爬上楼梯的最小损失)

    题目 On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you p ...

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

随机推荐

  1. Linux上db2安装

    Linux上db2安装:https://blog.csdn.net/nayanminxing/article/details/69372283

  2. 实现类似mysql group_concat的功能

    实现类似mysql group_concat的功能 SELECT SG.Id ,SG.GroupName ,HostNames = STUFF((SELECT ',' + SH.[HostName] ...

  3. 20145302张薇《Java程序设计》实验五报告

    20145302张薇 实验五:Java网络编程及安全 实验内容 掌握Socket程序的编写: 掌握密码技术的使用: 设计安全传输系统. 实验要求 基于Java Socket实现安全传输 基于TCP实现 ...

  4. 20145310 《Java程序设计》第6周学习总结

    20145310 <Java程序设计>第6周学习总结 教材学习内容总结 本周主要进行第十章和第十一章的学习. 第十章 Java将输入/输出抽象化为串流,数据有来源及目的地,衔接两者的是串流 ...

  5. linux安全第一周总结——20135227黄晓妍

    实验部分: 我将源代码做了修改,将其中一个数字修改为我学号27 2.在实验楼环境下将其保存为text.c并将其编译,得到text.s 3.将.开头的多余的语句删去了之后,我得到了32位环境的汇编代码 ...

  6. angularjs中的jqlite的认识理解及操作使用

    刚了解angularjs时,就知道它有个内嵌的轻量级的jquery:jqLite,那时候常于jQuery分不清,其实它们是不一样的.jqLite中,通过angular.element(param)获得 ...

  7. python-内置函数及捕获异常

    eval:把字符串转换成有效表达式 repr:把有效表达式转换成字符串 round(...) round(number[, ndigits]) -> number     Round a num ...

  8. Java Collections Framework 汇总

    1. Java Collections Framework Java集合框架概览 2. Java Collections Framework 之 RandomAccess接口 3. 关于ArrayLi ...

  9. ”由于没有远程桌面授权服务器可以提供许可证,远程会话被中断“的解决方案

    由于windows server 2012 R2 Datacenter 安装了 远程桌面角色,但是这个角色是120天免费的,需要购买授权的. 解决方案: 删除这个角色,就可以正常进行远程桌面连接了.但 ...

  10. 前端要不要学数据结构&算法

    我们都知道前端开发工程师更多偏向 DOM 渲染和 DOM 交互操作,随之 Node 的推广前端工程师也可以完成服务端开发.对于服务端开发而言大家都觉得数据结构和算法是基础,非学不可.所以正在进行 No ...