[LC] 70. 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
class Solution {
    public int climbStairs(int n) {
        if (n <= 2) {
            return n;
        }
        int preOne = 2;
        int preTwo = 1;
        int sum = 0;
        for (int i = 3; i <= n; i++) {
            sum = preOne + preTwo;
            preTwo = preOne;
            preOne = sum;
        }
        return sum;
    }
}
[LC] 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 解 ...
 - 377. Combination Sum IV 70. Climbing Stairs
		
back function (return number) remember the structure class Solution { int res = 0; //List<List< ...
 - Leetcode之70. Climbing Stairs Easy
		
Leetcode 70 Climbing Stairs Easy https://leetcode.com/problems/climbing-stairs/ You are climbing a s ...
 - 刷题70. Climbing Stairs
		
一.题目说明 题目70. Climbing Stairs,爬台阶(楼梯),一次可以爬1.2个台阶,n层的台阶有几种爬法.难度是Easy! 二.我的解答 类似的题目做过,问题就变得非常简单.首先用递归方 ...
 - LeetCode练题——70. Climbing Stairs
		
1.题目 70. Climbing Stairs——Easy You are climbing a stair case. It takes n steps to reach to the top. ...
 - [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 ...
 
随机推荐
- [CISCN2019 华北赛区 Day2 Web1]Hack World
			
知识点:题目已经告知列名和表明为flag,接下来利用ascii和substr函数即可进行bool盲注 eg: id=(ascii(substr((select(flag)from(flag)),1,1 ...
 - js判断苹果和安卓端或者wp端
			
最近做了一个H5,说要提供一个底部,可以区分安卓或者ios,到相应的网址进行下载APP,如图: 代码如下: window.onload = function () { var u = navigat ...
 - 37. docker swarm docker service 的更新
			
在service 运行的情况下 进行更新 1. 创建 名为 demo 的 overlay 网络 docker network create -d overlay demo 2. 创建 python-f ...
 - [kuangbin 带你飞] DP专题——HDU - 1024
			
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
 - Ubuntu---不能打开 exfat 文件系统格式的 U盘解决方法
			
出现问题:今天把 U 盘插入 Ubuntu 系统的电脑中,打开 U 盘发现弹出 系统格式不支持 的提醒,无法进入 U 盘进行操作. 环境: Ubuntu18.04 TSL; 格式化为 exfat 文件 ...
 - UML-领域模型-添加关联和属性
			
1.何谓关联? 关联(association):一个类的全局变量引用了另一个类,就表示关联了这个类 2.何时使用关联? 长时间(需要记住)留存的需要关联:短时间的不需要.比如: 需要关联:老师教那些课 ...
 - tensorflow C++接口调用图像分类pb模型代码
			
#include <fstream> #include <utility> #include <Eigen/Core> #include <Eigen/Den ...
 - Linux笔记(三)——Shell编程
			
预备知识 1.Shell是解释执行的脚本语言,可以直接调用Linux系统命令 2.文件以.sh结尾, #!bin/bash 标识, 说明这是一个shell脚本, 不能省略 3.执行 赋予权限,直接运行 ...
 - 9.windows-oracle实战第九课--plsql
			
一.oracle的pl/sql的概念 pl/sql是oracle在标准的sql语言上的扩展,不仅允许嵌入sql,还允许定义变量和常量,允许使用条件语句和循环语句,允许使用例外处理各种错误,这样使得它的 ...
 - PAT甲级——1077.Kuchiguse(20分)
			
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...