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 ...
随机推荐
- nginx实现动静分离--附nginx配置文件详解
转自http://www.cnblogs.com/1214804270hacker/p/9299462.html 一.认识访问静态资源与访问动态资源的区别 静态资源:指存储在硬盘内的数据,固定的数据, ...
- JMeterPlugin性能监控
GUI界面中的plugins manager中的jpgc-Standard set,其中共包含以下的文件: jpgc-dummy jpgc-fifo jpgc-graphs-basic jpgc-pe ...
- TCP Server有两个套接字
 TCP服务器有一个特殊的套接字,欢迎运行在任意主机上的客户进程的某些初始接触. 三次握手期间,客户进程敲服务器的欢迎之门.该服务器"听到"敲门时,它将生成一个新的TCP套接字对 ...
- 利用python 学习数据分析 (学习四)
内容学习自: Python for Data Analysis, 2nd Edition 就是这本 纯英文学的很累,对不对取决于百度翻译了 前情提要: 各种方法贴: https://w ...
- gitLab创建自己的私有库
一.创建私有库的流程简介 创建一个项目,留着后面的流程3制作私有库 在可以创建私有库的地方创建一个code repository, code repository是代码仓库,我们把代码上传到这个仓库. ...
- c常用函数
一.strtol long int strtol(const char *nptr, char **endptr, int base) strtol()会将nptr指向的字符串,根据参数base,按权 ...
- [BJOI2014]大融合(LCT)
题面 luogu bzoj是权限题.. 题解 \(LCT\)维护子树信息 因为\(LCT\)中有一些虚子树,\(splay\)维护不了. 所以要新开一个数组来记录 然后注意\(link\)时 是先\( ...
- Eclipse下,修改MAVEN 中央仓库地址,解决maven下载慢问题
作用于所有工作空间: 1.逐项打开:eclipse->preference->Maven->User Settings.按窗口中的User Settings文本框显示的路径,创建se ...
- 浏览器缓存如何控制? && 在url框中回车、F5 和 Ctrl + F5的区别是什么?
第一部分: 浏览器缓存如何控制? 最近在做网站,但是不知道缓存是什么东西怎么能行! 如何实现HTTP缓存呢? 下面我们来一步一步的探寻实现机制把. 方案一: 无缓存 说明: 浏览器向服务器请求 ...
- spring boot快速入门 2 :属性配置
属性配置:在application.properties中配置 第一步:配置端口号和项目名 并启动 第二步:在浏览器查看请求 第二种配置方式: 在application.yml中配置.(较为常用) 注 ...