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];

    }
};

最新文章

  1. RabbitMQ 将监听的IP从localhost修改为指定IP
  2. Erlang环境用eclipse搭建
  3. 【POJ】3744 Scout YYF I
  4. Requirejs加载超时问题的一个解决方法:设置waitSeconds=0
  5. LevelDB:一个快速轻量级的key-value存储库(译)
  6. slidingMenu默认显示菜单
  7. 配置使VirtualBox下的linux可以宿主机互访并上网
  8. HttpServlet请求重定向
  9. 编译lua5.3.2报错提示libreadline.so存在未定义的引用解决方法
  10. Nutch+Lucene搜索引擎开发实践
  11. 如何生成可变表头的excel(转)
  12. 11.3、Libgdx的音频之播放PCM音频
  13. vue项目tips
  14. HttpResonse 要记得关闭
  15. VS2017 配置QT5
  16. QT显示url图片
  17. Cron 表达式详解(已整理、很清晰)
  18. cdn刷新和对应的浏览器现象
  19. Session in BSU CodeForces - 1027F(思维 树 基环树 离散化)
  20. [svc][op]磁盘(结构)容量计算

热门文章

  1. 胜利大逃亡(杭电hdu1253)bfs简单题
  2. Software-Defined Networking A Comprehensive Survey --阅读_day2
  3. ThinkPHP5下自己写日志
  4. Thinkphp+ECharts生成柱状图
  5. Java 社区平台 - Sym 1.7.0 发布
  6. X86和X64环境下的基本类型所占用的字节大小
  7. JavaScript数组转字符串,字符串转数组
  8. OpenCV 图像特效
  9. Android 编程下的 TraceView 简介及其案例实战
  10. 常用的第三方模块 requests url