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 ...
随机推荐
- [转] Cisco路由器DNS配置
禁用Web服务 Cisco路由器还在缺省情况下启用了Web服务,它是一个安全风险.如果你不打算使用它,最好将它关闭.举例如下: Router(config)# no ip http server 配置 ...
- AWS 推出长期支持的 OpenJDK 免费分发版本 —— Amazon Corretto
简评:听说 Oracle JDK 要收费了,Oracle 要限制 Java 的商业或生产用途,针对这个问题,AWS 将会推出 Amazon Corretto. Java 是 AWS 用户使用的最流行的 ...
- Bootstrap Modal 关闭时右侧滚动条消失,页面左移的解决方法
问题描述:页面在打开Modal之前右侧有滚动条,Modal关闭之后,body中的class="modal-open"和style="padding-right: 17px ...
- .NET Core容器化之多容器应用部署-使用Docker-Compose
原文补充: -- docker-compose.ymlversion: ' services: mvc-web: container_name: mvc.web.compose build: . re ...
- UVALive-7457-Discrete Logarithm Problem(取模运算)
原题链接 额,一直在理解题意在纠结看不懂,后来才恍然大悟 题意:定义一种新运算 a × b = a * b mod p : 已知条件给定一个p 求 x 这里用到同余与模运算乘法公式:a * b % n ...
- es6学习 1
块级作用域绑定 一 var 声明及变量提升(Hoisting)机制 在函数作用域或全局作用域中通过 var 声明的变量,无论实际上是在哪里声明的,都会被当成在当前作用域顶部声明的变量,这就是我们常说的 ...
- Java switch函数
switch()函数中能放置的值为:byte,short,char,int,string,enum类型或者byte,short,char,int的包装类,其中,string类型是java7(含)之后才 ...
- CentOS 7下安装RabbitMQ
下载erlang:http://www.erlang.org/downloads ,otp_src_20.3.tar.gz 下载RabbitMQ: http://www.rabbitmq.com ,r ...
- Mac下包管理平台homebrew的使用
一.安装 参考:http://www.cnblogs.com/EasonJim/p/6287098.html 二.使用 假设我要安装node,命令如下: 安装软件 brew install node ...
- EasyMock set方法报错: java.lang.AssertionError
有返回值的方法没问题, 直接andReturn就行了. EasyMock.expect(info.getWebTitle()).andReturn(StringUtils.EMPTY).anyTime ...