[LintCode] Climbing Stairs 爬梯子问题
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?
Given an example n=3 , 1+1+1=2+1=1+2=3
return 3
LeetCode上的原题,请参见我之前的博客Climbing Stairs。
解法一:
class Solution {
public:
/**
* @param n: An integer
* @return: An integer
*/
int climbStairs(int n) {
) ;
vector<int> dp(n);
dp[] = ; dp[] = ;
; i < n; ++i) {
dp[i] = dp[i - ] + dp[i - ];
}
return dp.back();
}
};
解法二:
class Solution {
public:
/**
* @param n: An integer
* @return: An integer
*/
int climbStairs(int n) {
, b = ;
while (n--) {
b += a;
a = b - a;
}
return a;
}
};
[LintCode] Climbing Stairs 爬梯子问题的更多相关文章
- [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] 70. Climbing Stairs 爬楼梯问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] Min Cost Climbing Stairs 爬楼梯的最小损失
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- [LeetCode] 746. Min Cost Climbing Stairs 爬楼梯的最小损失
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- [LeetCode] 70. Climbing Stairs 爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- LintCode Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- climbing stairs(爬楼梯)(动态规划)
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [leetcode]70. Climbing Stairs爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- LeetCode 70. Climbing Stairs爬楼梯 (C++)
题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...
随机推荐
- testng 失败自动截图
testng执行case failed ,testng Listener会捕获执行失败,如果要实现失败自动截图,需要重写Listener的onTestFailure方法 那么首先新建一个Listene ...
- 魔镜VIP批量条形码视频教程
需要购买者请登我的淘宝店,https://cdrapp.taobao.com/ 优惠价哦!
- oracle中trunc()和to_char()函数用法
-----trunc(for date) select sysdate from dual; --当前时间 2016/9/7 10:32:04select trunc(sysdate) from d ...
- PHPCMS v9 安全防范教程
一.目录权限设置很重要:可以有效防范黑客上传木马文件.如果通过 chmod 644 * -R 的话,php文件就没有权限访问了.如果通过chmod 755 * -R 的话,php文件的权限就高了. 所 ...
- Webbench性能测试
1.下载安装:立即下载 官网:http://home.tiscali.cz/~cz210552/webbench.html 2.解压缩:tar -zxvf webbench-1.5.tar.gz 3 ...
- 安天移动安全应对“DressCode”威胁,发布企业移动威胁检查工具
近日,一种名为"DressCode"的恶意代码引起了国内安全行业的关注,该恶意代码以企业员工的移动设备作为跳板对企业内网进行攻击,对企业安全造成严重威胁.安天移动安全公司威胁情报团 ...
- locate 最快的查找文件的命令 NB
我见过最NB的查找文件最快的命令 [root@NB data]# locate teamviewer. /data/Software/teamviewer.i686.rpm /home/ok/.loc ...
- mongodb防火墙配置
http://ruby-china.org/topics/20128 https://docs.mongodb.com/manual/tutorial/configure-linux-iptables ...
- python 新手遇到的问题
作为新手,我把之前遇到的问题贴出来 错误提示1: TypeError: unbound method a() must be called with A instance as first argum ...
- 【Java EE 学习 72 上】【数据采集系统第四天】【增加调查logo】【文件上传】【动态错误页指定】【上传限制】【国际化】
增加logo的技术点:文件上传,国际化 文件上传的功能在struts2中是使用文件上传拦截器完成的. 1.首先需要在页面上添加一个文件上传的超链接. 点击该超链接能够跳转到文件上传页面.我给该表单页面 ...