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