leetcode70—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?
Note: Given n will be a positive integer.
Example 1:
Input: 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps
Example 2:
Input: 3 Output: 3 Explanation: There are three ways to climb to the top. 1. 1 step + 1 step + 1 step 2. 1 step + 2 steps 3. 2 steps + 1 step
想法:动态规划分解成子问题,到达n之前,走1步或者2步。即可表示成result[n]=result[n-1]+result[n-2]
class Solution {
public:
int climbStairs(int n) {
== n)
;
vector<);
result[] = ;
result[] = ;
; i <= n ;i++){
result[i] = result[i-] + result[i-];
}
return result[n];
}
};
leetcode70—Climbing Stairs的更多相关文章
- LeetCode70 Climbing Stairs
题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...
- LeetCode 70. 爬楼梯(Climbing Stairs)
70. 爬楼梯 70. Climbing Stairs 题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意: 给定 ...
- 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 ...
- [LeetCode] 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 ...
- Leetcode: climbing stairs
July 28, 2015 Problem statement: You are climbing a stair case. It takes n steps to reach to the top ...
- 54. Search a 2D Matrix && Climbing Stairs (Easy)
Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This m ...
- Climbing Stairs
Climbing Stairs https://leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It tak ...
- 3月3日(6) Climbing Stairs
原题 Climbing Stairs 求斐波那契数列的第N项,开始想用通项公式求解,其实一个O(n)就搞定了. class Solution { public: int climbStairs(int ...
随机推荐
- Codeforces729D(SummerTrainingDay01-F)
D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Linux中编译安装软件的基本流程
1. 准备软件包源文件 从互联网下载相应的软件包(以 .tar.gz 或 .tar.bz2 为后缀),将tarball文件解压到/usr/local/src目录下,并切换到软件包目录下 : 2. ./ ...
- H5添加禁止缩放功能
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scal ...
- a 链接点击下载
1. 将链接设置为.zip 结尾2.在a元素中添加download 属性,(目前只有chrome.firefox和opera支持) function download(src) { var $a = ...
- Nginx控制客户端请求的速率
使用ngx_http_limit_req_module模块的两个参数 ngx_http_limit_req_module模块用于限制每个IP访问每个定义key的请求速率 1.limit_req_zon ...
- webpack打包vue项目之后生成的dist文件该怎么启动运行
亲测,webpack打包vue项目之后生成的dist文件可以部署到 express 服务器上运行. 我的vue项目结构如下: 1. 进入该vue项目目录,打开git bash,执行:npm run b ...
- DOS中的ECHO命令详解
1. 作为控制批处理命令在执行时是否显示命令行自身的开关 格式:ECHO [ON|OFF] 如果想关闭“ECHO OFF”命令行自身的显示,则需要在该命令行前加上“@”. 2. 显示当前ECHO ...
- 【Zookeeper】Zookeeper集群单节点提供服务
以下只在特殊情况下使用,不要用在生产环境. 一.问题背景 公司的产品使用Zookeeper做为集群支持,但是客户在验收的时候提出了一个很为难人的要求,那就是3台集群服务,停止2台以后,还要求我们的应用 ...
- vs2017安装cuda9.0编译默认示例失败解决方法
https://devtalk.nvidia.com/default/topic/1027209/cuda-setup-and-installation/cuda-9-0-does-not-work- ...
- MariaDB数据表操作实例
1. MariaDB 数据库操作实例 MariaDB>create database class; //创建class数据库 MariaDB>use class; MariaDB>c ...