lintcode--爬台阶
来源:互联网 发布:java编写计算器源代码 编辑:程序博客网 时间:2024/04/29 19:14
题目
解答:
递归:
f(0) = 1;
f(1) = 1;
f(2) = f(1) + f(0);
f(m) = f(m-1) + f(m-2), m>=2;
代码:
public class Solution {
/**
* @param n: An integer
* @return: An integer
*/
public int climbStairs(int n) {
// write your code here
if(n == 0)
return 1;
if(n == 1)
return 1;
int a = 1;
int b = 1;
int c = 0;
for(int j = 0;j<n-1;j++){
c = a + b;
a = b;
b = c;
}
return c;
}
}
0 0
- lintcode--爬台阶
- 爬台阶
- 爬台阶问题
- 【动态规划】爬台阶
- 爬台阶(递归)
- 台阶
- 台阶
- 台阶
- 台阶
- LintCode-爬楼梯
- 爬楼梯-lintcode
- LintCode之爬楼梯
- lintcode爬楼梯
- LintCode | 111. 爬楼梯
- LintCode 爬楼梯[转载]
- 爬楼梯-LintCode
- Lintcode爬楼梯
- [Lintcode] #111 爬楼梯
- SQL Server资料整理
- Oracle I/O问题解析
- APC注入
- 联想Z470安装OSX10.11并成功驱动显卡、声卡、网卡
- tfyuiijo
- lintcode--爬台阶
- requirejs入门(三)
- 倍斯特快人一步 执着快充移动电源
- ubuntu命令之passwd
- R连接mysql数据库
- java 公式计算
- linux常见命令用法之(二)
- 剑指Offer-30-最小的k个数
- iOS将NavigationBar设置透明