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?

Note: Given n will be a positive integer.

Example 1:

Input: 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps

Example 2:

Input: 3
Output: 3
Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step
想法:动态规划分解成子问题,到达n之前,走1步或者2步。即可表示成result[n]=result[n-1]+result[n-2]
class Solution {
public:
    int climbStairs(int n) {
         == n)
            ;
        vector<);
        result[] = ;
        result[] = ;
         ; i <= n ;i++){
            result[i] = result[i-] + result[i-];
        }
        return result[n];

    }
};

leetcode70—Climbing Stairs的更多相关文章

  1. LeetCode70 Climbing Stairs

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

  2. LeetCode 70. 爬楼梯(Climbing Stairs)

    70. 爬楼梯 70. Climbing Stairs 题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意: 给定 ...

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

  4. [LeetCode] Climbing Stairs 爬梯子问题

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

  5. [LintCode] Climbing Stairs 爬梯子问题

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

  6. Leetcode: climbing stairs

    July 28, 2015 Problem statement: You are climbing a stair case. It takes n steps to reach to the top ...

  7. 54. Search a 2D Matrix && Climbing Stairs (Easy)

    Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This m ...

  8. Climbing Stairs

    Climbing Stairs https://leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It tak ...

  9. 3月3日(6) Climbing Stairs

    原题 Climbing Stairs 求斐波那契数列的第N项,开始想用通项公式求解,其实一个O(n)就搞定了. class Solution { public: int climbStairs(int ...

随机推荐

  1. Mysql添加字段.md

    alter table td_user add gender bit DEFAULT 0 COMMENT '性别';

  2. 【10-2】复杂业务状态的处理(从状态者模式到FSM)

    一.概述 我们平常在开发业务模块时,经常会遇到比较复杂的状态转换.比如说用户可能有新注册.实名认证中.已实名认证.禁用等状态,支付可能有等待支付.支付中.已支付等状态.OA系统里的状态处理就更多了. ...

  3. linux下使用sublime-text写coffee遇到的编译问题

    Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 556, i ...

  4. npm install、npm init、npm update、npm uninstall和package.json

    npm install 安装本地包 npm install <package_name>:这个命令将在当前目录中创建node_modules目录(如果尚不存在),并将该软件包下载到该目录. ...

  5. 更改Outlook 2013中Exchange数据文件存放路径

    昨天新入职目前所在的公司,在原公司一直都是直接使用Outlook设置用户名和密码后,然后将*.pst邮件的数据文件保存在其他盘符,以防止在更新操作系统时出现邮件丢失的情况:但是目前公司使用的是Exch ...

  6. vs中nuget命令的用法

    一.安装 1.安装指定版本类库install-package <程序包名> -version <版本号>        ( 注意:-version <版本号> 可以 ...

  7. JSTL核心标签库——<c:set>标签、<c:out>标签

    <c:set>标签 index.jsp <%@ page import="java.util.Map" %> <%@ page import=&quo ...

  8. windows下安装并启动hadoop2.7.2

    64位windows安装hadoop没必要倒腾Cygwin,直接解压官网下载hadoop安装包到本地->最小化配置4个基本文件->执行1条启动命令->完事.一个前提是你的电脑上已经安 ...

  9. 解决 web.xml is missing and <failOnMissingWebXml> is set to true 报错

    在学习maven模块化构建项目的时候遇到了如下报错信息: web.xml is missing and <failOnMissingWebXml> is set to true. 这时候需 ...

  10. UI第二组与数据库对接时遇到的问题记录

    此为组内某一位做UI的同学的随笔. 之前的app由于没有加入数据库,所以每次重新启动里面的东西都会回到初始状态,即不能保存内容.我们的数据库小组已经很棒地基本完成了数据库的工作,于是我就准备加入数据库 ...