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 ...
随机推荐
- PHP错误——Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)
解释是可用内存已耗尽,这关系到PHP的memory_limit的设置问题. 这里有两种方法解决 1.修改php.ini memory_limit = 128 打开终端输入下列bash命令 cd /pr ...
- AssertJ断言系列-----------<数据库断言三>
其实,是有很多种数据断言的使用.那么,我们在接口的测试中,到底应不应该加上数据库断言呢?我的观点是,视情况而定:某一些特殊的场景或者特殊的业务,那么我们就一定要加上数据库断言.不是我们测试人员,不相信 ...
- C#-WebForm-ajax状态保持
cookies: ashx端赋值: context.Response.Cookies["Username"].Value = ""; 后台端加载: Respon ...
- JAVA编程思想第一章——对象导论
- [转] org.scalatest.FunSuite Scala Examples - Scala FunSuite 测试的例子
[From] https://www.programcreek.com/scala/org.scalatest.FunSuite org.scalatest.FunSuite Scala Examp ...
- Mac下安装Iterm2终端工具
一般Iterm2是结合oh-my-zsh一起使用,但是如果不喜欢zsh也可以单独使用.Iterm2有个亮点就是可以通过快捷键快速启动. 安装步骤: 1.下载: http://www.iterm2.co ...
- 【JAVA-WEB】在url上追加sessionid
HttpSession session = request.getSession(); url = url+";jsessionid="+session.getId();
- 关于javascript的各种高宽
- sql中COUNT(*)、COUNT(字段名)的区别
数据表:其中IT002的Fname是null. 执行sql: ) FROM T_Employee 结果: 结论:COUNT(*)统计的是结果集的总条数,而COUNT(FName)统计的则是除了结果集中 ...
- 12.Proxy
1.概述 Proxy 用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种“元编程”(meta programming),即对编程语言进行编程. Proxy 可以理解成,在目标对象之前架 ...