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. 为什么要用lock 【readonly】object?为什么不要lock(this)?

    一. 为什么要用lock,lock了什么? 当我们使用线程的时候,效率最高的方式当然是异步,即各个线程同时运行,其间不相互依赖和等待.但当不同的线程都需要访问某个资源的时候,就需要同步机制了.也就是说 ...

  2. HDU4283(KB22-G)

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. 第三十四天- 线程队列、线程池(map/submit/shutdown/回调函数)

    1.线程列队 queue队列 :使用import queue,用法与进程Queue一样 class queue.Queue(maxsize=0) # 先进先出: q = queue.Queue(3) ...

  4. python短信发送

    '''以云之讯平台为例:''' url = 'https://open.ucpaas.com/ol/sms/sendsms' # 账户sidsid = 'f0ad70b276a8b63eb44f415 ...

  5. HTML meta 标签总结

    本文转载自:http://www.cnblogs.com/lovesong/p/5745893.html meta标签作用 META标签是HTML标记HEAD区的一个关键标签,提供文档字符集.使用语言 ...

  6. android开发之braodCast

    广播问题: 遇到了broadcast中sendBroadcast之后,注册registerReceiver的receiver接受不到广播,原因是permisson权限问题. 自定义的permissio ...

  7. IDEA报错:Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. ('crmWatcherService'错误)

    单表插入项目,插入前正常,插入后运行webapplication报错: run: debug: 于webapplication报错: Injection of autowired dependenci ...

  8. aix rootvg镜像

    就一般生产系统而已,操作系统层面都要进行备份,而最常见的操作系统备份方式之一就是做镜像(mirror),而实践过程中,往往是把rootvg这个卷组做镜像操作.查看rootvg是否已经进行镜像方法: 1 ...

  9. [SQLServer大对象]——FileTable初体验 (转载)

    阅读导航启用FILESTREAM设置更改FILESTRAM设置启用数据库非事务性访问级别FileTable 在我接触FileTable之前,存储文件都是存储文件的链接和扩展名到数据,其实并没有实际的把 ...

  10. sysbench使用

      1 部署 1.1 官方主页 https://github.com/Percona-Lab/sysbench-tpcc https://github.com/akopytov/sysbench 1. ...