Climbing Stairs
2015-07-29 14:46
477 查看
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?
这是一个简单的Fibonaci问题,只是前三个元素应为0,1,2.
Each time you can either climb 1 or 2 steps. In how many distinct
ways can you climb to the top?
这是一个简单的Fibonaci问题,只是前三个元素应为0,1,2.
public int climbStairs(int n) { if(n<=2)return n; long one=1,two=2,now=0; for(int i=3;i<=n;i++){ now=one+two; one=two; two=now; } return (int) now; }
相关文章推荐
- UVA 10976 - Fractions Again?!
- http://blog.csdn.net/ym19860303/article/details/8462450
- HDU-5319 Painter
- 关于RAID
- 2015 Multi-University Training Contest 3 RGCDQ
- Painter(模拟)
- 在服务 ObtainData 实现的协定列表中找不到协定名称 "IMetadataExchange"。将 ServiceMetadataBehavior 添加到配置文件或直接添加到 ServiceHost,以启用对该协定的支持。
- 有关Error - RtlWerpReportException failed with status code :-1073741823.的解决方法
- HDU 1021 Fibonacci Again
- HDU 5319 Painter
- gensim安装http://blog.csdn.net/helihongzhizhuo/article/details/47038575
- Failed to push selection: Read-only file system的解决方法
- zz 通过INFORMATION_SCHEMA.INNODB_TRX、INNODB_LOCKS、INNODB_LOCK_WAITS 三个表获取事务与锁的信息
- 2015 Multi-University Training 3 多校集训 第三场 部分题解及反思
- [模拟] 多校联合第三场 painter HDU 5319
- 2015 Multi-University Training Contest 3 1004
- hdu5319(2015多校3)--Painter(暴力,,,)
- async & await 的前世今生(Updated)
- hdu 5319 Painter 2015 Multi-University Training Contest 3
- SVN svnserve.conf: Option expected 的解决方法 以及 Authorization failed 的解决方法