LeetCode OJ: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?
Subscribe to see which companies asked this question
简单的dp问题,代码如下:
class Solution {
public:
int climbStairs(int n) {
if(n <= )
return n;
dp.resize(n + );
dp[] = ;
dp[] = ;
for(int i = ; i < n + ; ++i){
dp[i] += dp[i - ];
dp[i] += dp[i - ];
}
return dp[n];
}
private:
vector<int> dp;
};
java版本代码如下所示:
public class Solution {
public int climbStairs(int n) {
if(n < ) return n;
int dp [] = new int [n+];
dp[] = ;
dp[] = ;
for(int i = ; i <= n; ++i){
dp[i] = dp[i-] + dp[i-];
}
return dp[n];
}
}
LeetCode OJ:Climbing Stairs(攀爬台阶)的更多相关文章
- Leetcode#70. Climbing Stairs(爬楼梯)
题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解 ...
- 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 OJ]-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(爬楼梯)(动态规划)(*)
翻译 你正在爬一个楼梯. 它须要n步才干究竟顶部. 每次你能够爬1步或者2两步. 那么你有多少种不同的方法爬到顶部呢? 原文 You are climbing a stair case. It tak ...
- LeetCode OJ——Climbing Stairs
http://oj.leetcode.com/problems/climbing-stairs/ 走台阶的题目,转换出数学模型之后,就是Fibonacci数列.后一个数等于前两个数的和. 递归版本超时 ...
- [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 ...
- 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 ...
- LeetCode746 Min Cost Climbing Stairs(爬上楼梯的最小损失)
题目 On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you p ...
- 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 ...
随机推荐
- go channel 阻塞
初接触 go 有不对得请解释下 Channel是goroutine之间进行通信的一种方式,先看下面代码为什么会阻塞: func closer(ch chan int) { ch <- 1 log ...
- 20135320赵瀚青LINUX内核分析第四周学习笔记
赵瀚青原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 概述 本周的内容主要是讲解系 ...
- JavaScript中字符操作之大小写转换
1.toUpperCase() 方法用于把字符串转换为大写 var str = prompt("请输入需转换大写的字符串:"); str = str.toUpperCase() ...
- Leetcode(93): Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- rocketMQ基本理解
消息中间件需要解决哪些问题? Publish/Subscribe 发布订阅是消息中间件的最基本功能,也是相对于传统RPC通信而言. Message Priority 规范中描述的优先级是指在一个消息队 ...
- Spring Container的扩展点
转自: http://blog.csdn.net/kkdelta/article/details/5488430 Spring在解析完配置文件后,会调用一些callback方法,使用Spring的开发 ...
- jsp选项卡导航实现——模板
效果 刚进来页面的样子 在第二个选项卡上方时 点击后 离开 同样第三个 点击 移走鼠标 代码 <%@ page contentType="text/html;charset=UTF-8 ...
- 关于Visual Studio 2010自动添加头部注释信息
作为一个万年潜水党,不关这一篇文章技术含量如何,也算是一个好的开始吧. 在日常的开发中我们经常需要为类库添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们 ...
- vcf2maf
1.https://github.com/mskcc/vcf2maf 2.https://github.com/cbare/vcf2maf
- VS2012 创建 WebService
1.文件——新建——项目——Visual C#——Web——ASP.NET 空 Web 应用程序. 2.右键项目——添加——新建项——Web——Web 服务. 3.按 F5 启动调试,浏览器将显示接口 ...