1、题目

70. Climbing Stairs——Easy

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

2、我的解答

 # -*- coding: utf-8 -*-
# @Time : 2020/2/16 14:03
# @Author : SmartCat0929
# @Email : 1027699719@qq.com
# @Link : https://github.com/SmartCat0929
# @Site :
# @File : 70. Climbing Stairs.py class Solution:
def climbStairs(self, n: int) -> int:
if n < 3:
return n
count1, count2 = (1, 2)
for i in range(2, n):
count = count1 + count2
count1 = count2
count2 = count
return count print(Solution().climbStairs(11))

LeetCode练题——70. Climbing Stairs的更多相关文章

  1. 刷题70. Climbing Stairs

    一.题目说明 题目70. Climbing Stairs,爬台阶(楼梯),一次可以爬1.2个台阶,n层的台阶有几种爬法.难度是Easy! 二.我的解答 类似的题目做过,问题就变得非常简单.首先用递归方 ...

  2. [LeetCode&Python] Problem 70. Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  3. 【leetcode❤python】70. Climbing Stairs

    #Method1:动态规划##当有n个台阶时,可供选择的走法可以分两类:###1,先跨一阶再跨完剩下n-1阶:###2,先跨2阶再跨完剩下n-2阶.###所以n阶的不同走法的数目是n-1阶和n-2阶的 ...

  4. [刷题] 70 Climbing Stairs

    要求 楼梯共有n个台阶,每次上一个台阶或两个台阶,一共有多少种上楼梯的方法? 示例 输入:n=3 [1,1,1],[1,2,],[2,1] 输出:n=3 实现 自顶向下(递归) 递归 1 class ...

  5. Leetcode之70. Climbing Stairs Easy

    Leetcode 70 Climbing Stairs Easy https://leetcode.com/problems/climbing-stairs/ You are climbing a s ...

  6. [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 ...

  7. 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 ...

  8. Leetcode#70. Climbing Stairs(爬楼梯)

    题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解 ...

  9. 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 ...

随机推荐

  1. 第三十二篇 玩转数据结构——AVL树(AVL Tree)

          1.. 平衡二叉树 平衡二叉树要求,对于任意一个节点,左子树和右子树的高度差不能超过1. 平衡二叉树的高度和节点数量之间的关系也是O(logn) 为二叉树标注节点高度并计算平衡因子 AVL ...

  2. S3C2440之存储控制器学习记录

    /==========翻译S3C2440存储控制器部分================/ 5 存储控制器 概述 S3C2440内存控制器为外部存储访问提供内存控制信号. S3C2440A有如下特征: ...

  3. winform学习(10)设置控件透明背景色

    如何将控件的背景色设置为透明 ①将属性BackColor设置为Web--Transparent ②将属性FlatStyle设置为Flat 如果想将边框去掉: 将属性FlatAppearance下的Bo ...

  4. 【渗透测试】ZipperDown 漏洞分析

    0x01 漏洞危害 1. 在使用 HTTP 下载 zip 包并使用有问题的第三方库 unzip 时,攻击者通过劫持 HTTP 流量,可以导致 APP 下载一个恶意的 zip 包,在解压 zip 包时可 ...

  5. java到js的中文无法显示,中文显示位(?)

    今天遇到这么一个问题,用js调用java的get请求,得到的json数据中中文无法正常显示,jsp文件中都是申明utf-8格式的,查询了一番,发现问题出现在@ResponseBody上 @Respon ...

  6. 分享链接在QQ内总是被多人举报怎么办,域名防红的方案

    背景 相信大家经常会遇到一个头疼的问题就是,自己的推广链接会因多人投诉举报导致链接在QQ内转发分享会被QQ管家拦截,用户无法打开访问的问题. 那么当大家遇到这个问题的时候应该怎么办呢?不用急,下面分享 ...

  7. linux搭建常用命令

    nohup java -jar floodlight.jar >log.txt     运行jar,日志打印到log.txt中netstat -lnp|grep 88            查看 ...

  8. [lua]紫猫lua教程-命令宝典-L1-01-01. Lua环境与IDE

    网上大把的lua教程  不过紫猫老师的教程向来都是讲的非常仔细 所以最近天气已经36+了 魔兽世界还需要冲飞行声望  懒得写单子根本没有单子,正好认认真真的看下紫猫老师的lua教程 紫猫老师的lua教 ...

  9. linux shell ansible 命令详解

    也可以参考ansible 模块介绍的其他文章:https://www.cnblogs.com/guxiaobei/p/8316903.html 安装ansible yum install epel-r ...

  10. php的排序函数

    sort(array,sortingtype); 参数 描述 array 必需.规定要进行排序的数组. sortingtype 可选.规定如何比较数组的元素/项目.可能的值: 0 = SORT_REG ...