Lintcode 111.爬楼梯
来源:互联网 发布:淘宝开店考试 编辑:程序博客网 时间:2024/06/05 07:06
假设你正在爬楼梯,需要n步你才能到达顶部。但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部?
样例
比如n=3,1+1+1=1+2=2+1=3,共有3种不同的方法
返回 3
思路:一共n层楼梯,每次爬一层或俩层
class Solution {public: /** * @param n: An integer * @return: An integer */ int climbStairs(int n) { // write your code here if(n==0) return 0; if(n==1) return 1; int f[n+1]; f[0]=f[1]=1; for(int i=2;i<=n;i++) { f[i]=f[i-1]+f[i-2]; } return f[n]; }};
阅读全文
0 0
- LintCode | 111. 爬楼梯
- Lintcode 111.爬楼梯
- Lintcode 111. 爬楼梯
- LintCode-爬楼梯
- 爬楼梯-lintcode
- LintCode之爬楼梯
- lintcode爬楼梯
- LintCode 爬楼梯[转载]
- 爬楼梯-LintCode
- Lintcode爬楼梯
- [Lintcode] #111 爬楼梯
- 爬楼梯-LintCode
- LintCode 爬楼梯
- LintCode Climbing Stairs 爬楼梯
- LintCode:动态规划 爬楼梯
- Lintcode-动态规划-爬楼梯
- LintCode(easy)111.爬楼梯(bug集)
- LintCode | Easy | 爬楼梯 | Climbing Stairs
- 坚持的重要性
- C#中数组、ArrayList和List三者的区别
- RecyelerView适配和点击事件
- 面试题--精选Hadoop选择题
- php 7 新特性
- Lintcode 111.爬楼梯
- 区块链开发教程: 使用Javascript发送数据到区块链
- 开发工程师必会的Linux命令
- 人工智能为什么率先应用在这七个领域?
- 比特币挖矿——钱包
- HTML标签
- iOS中求出label中文字的行数和每一行的内容,带自定义行间距
- 检测四边形(多边形)
- 非常有用的Java程序片段