LeetCode Climbing Stairs
来源:互联网 发布:淘宝 上下架时间 编辑:程序博客网 时间:2024/06/11 06:10
题目
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?
到第i格的路线数n(i)=n(i-1)+n(i-2),由此递推即可。
代码:
class Solution {public: int climbStairs(int n) { if(n<3)return n;int nw1=1,nw2=2,nw;//到当前格前两格的路线数,前一个的路线数,当前格的路线数for(int i=3;i<=n;i++){nw=nw1+nw2;nw1=nw2;nw2=nw;}return nw; }};
0 0
- LeetCode: Climbing Stairs
- LeetCode: Climbing Stairs
- [LeetCode]Climbing Stairs
- LeetCode Climbing Stairs
- [Leetcode] Climbing Stairs
- Leetcode: Climbing stairs
- LeetCode Climbing Stairs
- [LeetCode] Climbing Stairs
- leetcode 107: Climbing Stairs
- [LeetCode] Climbing Stairs
- [LeetCode]Climbing Stairs
- [leetcode]Climbing Stairs
- LeetCode-Climbing Stairs
- [leetcode] Climbing Stairs
- LeetCode - Climbing Stairs
- LeetCode:Climbing Stairs
- Leetcode Climbing Stairs
- LeetCode | Climbing Stairs
- 敏捷开发一千零一夜读书笔记之敏捷初探
- 第一篇博客
- Hdu 1507 Uncle Tom's Inherited Land*
- qt 调试
- Ural 1998 The old Padawa
- LeetCode Climbing Stairs
- Linux设备驱动程序学习笔记04:字符设备驱动程序II
- 查询oracle比较慢的session和sql
- 《数据结构》--严蔚敏 静态链表排序 p270
- hdu 1507 最大匹配 Uncle Tom's Inherited Land* 黑白块的思想,有效分成两部分
- jQuery选择器总结
- eclipse 自动为getter和setter添加中文注释
- Shortest Prefixes
- 对象不支持“addEventListener”属性或方法