LeetCode ClimbingStairs
class Solution {
public:
int climbStairs(int n) {
if (n < ) return ;
int a = ;
int b = ;
for (int i=; i<n; i++) {
int t = a + b;
a = b;
b = t;
}
return b;
}
};
发现leetcode上的题目很多也在剑指offer里有,这题也是,实际上算一个fab数列,因为对于一个n,可以先走一步,也可以先走两步,前者剩下n-1个台阶,后者剩下n-2,而假设我们已经求的(n-1)和(n-2)个台阶时的种数,这时f(n) = f(n-1) + f(n-2)
LeetCode ClimbingStairs的更多相关文章
- leetcode — climbing-stairs
/** * * Source : https://oj.leetcode.com/problems/climbing-stairs/ * * * You are climbing a stair ca ...
- LeetCode(70)题解: climbing-stairs
https://leetcode.com/problems/climbing-stairs/ 题目: You are climbing a stair case. It takes n steps t ...
- [LeetCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- leetcode算法分类
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...
- Leetcode: climbing stairs
July 28, 2015 Problem statement: You are climbing a stair case. It takes n steps to reach to the top ...
- LeetCode题目分类
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...
- <转>LeetCode 题目总结/分类
原链接:http://blog.csdn.net/yangliuy/article/details/44514495 注:此分类仅供大概参考,没有精雕细琢.有不同意见欢迎评论~ 利用堆栈:http:/ ...
- [LeetCode]题解(python):070-Climbing Stairs
题目来源: https://leetcode.com/problems/climbing-stairs/ 题意分析: 爬楼梯,一次可以爬一步或者两步.如果要爬n层,问一共有多少种爬法.比如说,如果是3 ...
- LeetCode——Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
随机推荐
- 读取Properties文件的六种方法
1.使用java.util.Properties类的load()方法 示例: InputStream in = new BufferedInputStream(new FileInputStream( ...
- spring中scope的prototype与singleton区别
最近在研究单例模式,突然想起项目中以下配置,scope="singleton" 和 scope="prototype"到底有何区别呢?以下做下简要分析. < ...
- eclipse远程debug服务器上的项目(Tomcat),打开、关闭及常见错误汇总
我们工作中,有时候测试/生产环境,出现的结果会与我们预计的不一样,只看代码又看不出去问题所在,这个时候就需要远程debug下服务器上的项目. 注意:(1)需要debug的代码,本机代码需与服务器上一致 ...
- sourceTree"重置提交"和"提交回滚"的区别
相信用过sourceTree的伙伴们都认识这两,但是不一定用过这两个功能,甚至是不能很好的把握它两的区别,根据自己最近亲身测试,总算是能小小的总结一下了 首先这儿假如,历史版本已经出现了1.2.3.4 ...
- 【2】JMicro微服务-Hello World
如非授权,禁止用于商业用途,转载请注明出处作者:mynewworldyyl 1. 首先完成 JMicro微服务-RPC体验 的1到5步. 按默认方式启动ZK及Redis: JDK需要Java8及以上. ...
- Docker安装MongoDb
1.下载镜像 docker pull mongo 2.运行mongo docker run --name mongo -v /data/mongodb:/data/db -p : -d mongo - ...
- open/read/write/close
open 函数 函数原型 #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int o ...
- IIS7如何实现访问HTTP跳转到HTTPS访问 转的
加几句,1.安装url重写模块,不需要重启IIS,安装完了就能用.个人感觉比 IIS REWRITE组件更好用,iis rewrite是安装第三方的那种,不缴费只可以把所有规则写在一起,不能区别站点, ...
- 单独安装VS2012装mono for android
直接安装个SQL Server2012,然后就可以单独安装VS2012 来用mono for android了.如果不想装,那就装以下这些东西. 广州-PC286() 11:05:28 和 x86 ...
- 五一,期待一场这样的旅行,提前预祝Csdner五一快乐
五一,期待一场这样的旅行,提前预祝Csdner五一快乐 五一,你是否期待一次这样的旅行: 住在一间安静优美的小屋,在鸟鸣中起床,推窗有花香铺面而来.早餐过后,在阳光温暖的抚摸里,骑车踏青或光脚奔跑. ...