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 ...
随机推荐
- CSS 关于屏幕适配REM
这里不多说了,想详细了解的可以参考 2350305682 的博客 https://www.cnblogs.com/annie211/p/8118857.html 不想多深究,想先实现的看这(移动端): ...
- BZOJ3601 一个人的数论
Description 定义 \[ f_k(n)=\sum_{\substack{1\leq i\leq n\\gcd(i,n)=1}}i^k \] 给出\(n=\prod_{i=1}^w p_i^{ ...
- LOJ#6085. 「美团 CodeM 资格赛」优惠券(set)
题意 题目链接 Sol 考虑不合法的情况只有两种: 进去了 再次进去 没进去 但是出来了 显然可以用未知记录抵消掉 直接开个set维护一下所有未知记录的位置 最优策略一定是最后一次操作位置的后继 同时 ...
- MySql循环语句
drop procedure if exists test_insert; DELIMITER ;; CREATE PROCEDURE test_insert () BEGIN DECLARE i I ...
- Java 根据出生日期计算年龄
1.把出生日期字符串转换为日期格式. public static Date parse(String strDate) throws ParseException { SimpleDateFormat ...
- 高德地图 JS API - 根据经纬度获取周边建筑地标
像我们经常用的微信或微博,发表动态时都有选择位置的功能,根据当前的定位获取附近的地标.利用高德地图我们就可以实现这样的功能. 1. 具体代码: // 高德地图查询周边 function aMapSea ...
- Maven学习(六)maven使用中遇到的坑
坑1:使用eclipse构建web项目时,pom.xml中 <packaging>war</packaging> 报错 eclipse给出的报错信息提示是:web.xml is ...
- js判断数组是否包含某个字符串变量
最近碰到一个这样的现象,后台返回的数据中,数组里面有一些有变量值,有一些没有变量值. 举个例子,比如后台返回的例子是这样的: var arr=[ { "status":" ...
- LeetCode题解之Binary Number with Alternating Bits
1.题目描述 2.问题分析 将数值转换为二进制,然后将前面的 0 去掉,再遍历一边二进制字符串,对每个字符和其后部的字符进行比较. 3.代码 bool hasAlternatingBits(int n ...
- 购物商城学习--第三讲(tomcat插件启动web工程)
此处提到的tomcat插件即maven工程集成的tomcat插件,可以在添加maven的tomcat插件之后,在本地通过脚本或者命令行方式运行web工程,tomcat插件启动只需要修改一个端口即可,非 ...