[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 ...
随机推荐
- Windows Server 2012 R2桌面化详细设置图解
一.任务栏左下角启动服务器管理器,然后进行设置. 1.登录不显示服务器管理器 2.本地服务器,看到右边的IE增强的安全配置,如图所示,关闭两项内容.这样就关闭了IE增强安全提示框. 3.“工具”菜单, ...
- FreeCodeCamp心得
<img> <input> tags are self-closing. So that there is only one tag without a slash i ...
- 使用zxing生成二维码
public static Bitmap Create2DCode(String str) throws WriterException { // 生成二维矩阵,编码时 ...
- Shell 获取指定行的内容
需求: 有一个文件,根据指定的字符串,得到该字符串上两行的内容. 文件内容如下: linux-56:# cat sys.ttconnect.ini # Copyright (C) 1999, 2006 ...
- hbase 遇到过的问题
1:下面这个错误是因为我zookeeper忘了启动了,启动你的zookeeper,重新启动下你的hbase hbase(main):002:0> list TABLE ERROR: Can't ...
- ubuntu下设置数据库字符集
就linux环境下出现的数据库乱码的问题,以ubuntu为例进行的总结 ubuntu环境设置的字符集utf8,windows默认字符集是GBK,Ubuntu的默认字符集为utf-8,这使 得在用tel ...
- FPGA 开发笔记 点滴
1.添加包含的文件或参数文件(define.v)的方式:如果文件在工程目录下的一个文件夹下,则可用 `include "../文件夹名/define.v", 文件和工程载同一目录 ...
- Delphi控件之---通过编码学习TStringGrid(也会涉及到Panel控件,还有对Object Inspector的控件Events的介绍
我是参考了万一的博客里面的关于TStringGrid学习的教程,但是我也结合自己的实际操作和理解,加入了一些个人的补充,至少对我有用! 学用TStringGrid之——ColCount.RowCoun ...
- Delphi容器类之---TList、TStringList、TObjectList,以及一个例程的代码分析
转载自:http://blog.csdn.net/jqandjq/article/details/5429137 看了这里标题,大家可能以为我会谈TListBox控件,那就错了.我要谈的是Delphi ...
- Codeigniter的Redis使用
1. ./config/redis.php: <?php $config['redis_host'] = '127.0.0.1'; $config['redis_port'] = '6379'; ...