【一天一道LeetCode】#70. Climbing Stairs
一天一道LeetCode
本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github
欢迎大家关注我的新浪微博,我的新浪微博
欢迎转载,转载请注明出处
(一)题目
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?
(二)解题
题目大意:从零开始每次跳一步或者两步,跳到N总共有多少种不同的跳法。
很典型的动态规划问题,状态转移方程为,dp[n] = dp[n-1]+dp[n-2]。
class Solution {
public:
int climbStairs(int n) {
int dp[n];//纪录跳到i的不同路径的个数
if(n==0) return 1;//0的时候返回1
if(n==1) return 1;
dp[0] = 1;
dp[1] = 1;
for(int i = 2 ; i <= n ; i++)
{
dp[i] = dp[i-1]+dp[i-2];//按状态转移方程进行计算
}
return dp[n];//返回跳到n的次数
}
};
【一天一道LeetCode】#70. Climbing Stairs的更多相关文章
- LN : leetcode 70 Climbing Stairs
lc 70 Climbing Stairs 70 Climbing Stairs You are climbing a stair case. It takes n steps to reach to ...
- 42. leetcode 70. Climbing Stairs
70. Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time y ...
- Leetcode#70. Climbing Stairs(爬楼梯)
题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解 ...
- [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 爬楼梯
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 (爬楼梯) 解题思路和方法
Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you ...
- LeetCode 70 Climbing Stairs(爬楼梯)(动态规划)(*)
翻译 你正在爬一个楼梯. 它须要n步才干究竟顶部. 每次你能够爬1步或者2两步. 那么你有多少种不同的方法爬到顶部呢? 原文 You are climbing a stair case. It tak ...
- Java [Leetcode 70]Climbing Stairs
题目描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either ...
- [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 ...
随机推荐
- random 模块
import stringprint (random.random()) # 0-1之间选浮点数print (random.randint(0,99,))#0-99之间选任意整数print (rand ...
- Noip2017 普及 T3 Chess
神奇的场上原码 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...
- Hadoop加速器GridGain
GridGain的Hadoop加速器 像GridGain等内存网格产品(IMDG)不仅可以作为简单的缓存,加速Hadoop中MapReduce计算也是IMDG的一个亮点.这样内存计算领域又多了一种思路 ...
- JVM初探- 使用堆外内存减少Full GC
JVM初探-使用堆外内存减少Full GC 标签 : JVM 问题: 大部分主流互联网企业线上Server JVM选用了CMS收集器(如Taobao.LinkedIn.Vdian), 虽然CMS可与用 ...
- miracl去除某些特殊信息
只需要在mirdef.h中增加定义 #define MR_STRIPPED_DOWN 即可在编译的时候,去掉错误信息 #define MIRACL 32 #define MR_LITTLE_ENDI ...
- OpenResty 自定义 access_log 格式
定义access log的format是 Nginx已经提供的功能,有了 ngx_lua 之后就可以更灵活的记录请求相关的信息,而不仅仅拘泥于 Nginx的内置变量了,可以自定义一些格式和变量来存储结 ...
- Scala:字符串
http://blog.csdn.net/pipisorry/article/details/52902348 Scala字符串 在 Scala 中,字符串的类型实际上是 Java String,它本 ...
- 一道有趣的Twitter技术面试题
来自:http://blog.jobbole.com/50705/ 看下面这个图片” “在这个图片里我们有不同高度的墙.这个图片由一个整数数组所代表,数组中每个数是墙的高度.上边的图可以表示为数组[2 ...
- shell命令执行hive脚本(hive交互,hive的shell编程)
Hive执行方式 Hive的hql命令执行方式有三种: 1.CLI 方式直接执行 2.作为字符串通过shell调用hive –e执行(-S开启静默,去掉"OK","Tim ...
- mysql进阶(二十八)MySQL GRANT REVOKE用法
mysql进阶(二十八)MySQL GRANT REVOKE用法 MySQL的权限系统围绕着两个概念: 认证->确定用户是否允许连接数据库服务器: 授权->确定用户是否拥有足够的权限执 ...