Lintcode 111. 爬楼梯
来源:互联网 发布:数据修炼系统下载 编辑:程序博客网 时间:2024/06/04 19:54
public class Solution { /** * @param n: An integer * @return: An integer */ public int climbStairs(int n) { // write your code here if(n==1){ return 1; } else if(n==2){ return 2; } int num1 = 1; int num2 = 2; int result = 0; for(int i=2;i<n;i++){ result = num1+num2; num1 = num2; num2 = result; } return result; }}
斐波那契数列 F(N)=F(N-1)+F(N-2)
可以用递归来做,用递归时,当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
- 在app内打开URL,ccui.WebView 或者 cc.sys.OpenUrl('rul')
- TMeter Premium(宽带仪表软件)官方正式版V16.0.860下载
- s5pv210-裸机之SD卡
- 模拟实现strstr
- MYSQL输入查询
- Lintcode 111. 爬楼梯
- JavaScript的闭包
- Android模拟器Genymotion安装使用教程详解
- 密码6-20位,只允许字母、数字、下划线其中两项
- python爬虫入门篇------爬取网页源代码
- bzoj 1178: [Apio2009]CONVENTION会议中心 倍增+set
- html5_ionic_侧拉练习
- sql语句where条件优化
- hdu FatMouse' Trade