题目描述:

中文:

假设你正在爬楼梯。需要 n 阶你才能到达楼顶。

每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?

注意:给定 n 是一个正整数。

英文:

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.

class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
dp = [1 for i in range(n+1)]
for i in range(2, n+1):
dp[i] = dp[i-1] + dp[i-2]
return dp[n]

题目来源:力扣

力扣—climbing stairs(爬楼梯) python实现的更多相关文章

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

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

  3. [LeetCode] Min Cost Climbing Stairs 爬楼梯的最小损失

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  4. climbing stairs(爬楼梯)(动态规划)

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

  5. [LeetCode] 746. Min Cost Climbing Stairs 爬楼梯的最小损失

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  6. Climbing Stairs爬楼梯——动态规划

    题目描写叙述: 初阶:有n层的台阶,一開始你站在第0层,每次能够爬两层或者一层. 请问爬到第n层有多少种不同的方法? 进阶:假设每次能够爬两层.和倒退一层,同一个位置不能反复走,请问爬到第n层有多少种 ...

  7. LeetCode 70. Climbing Stairs爬楼梯 (C++)

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

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

  9. [Leetcode] climbing stairs 爬楼梯

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

随机推荐

  1. linux下的软链接与硬链接

    在 Linux 底下的连结档有两种,一种是类似 Windows 的快捷方式功能的文件,可以让你快速的链接到目标文件(或目录);这种链接称为软链接. 另一种则是透过文件系统的 inode 连结来产生新档 ...

  2. UVA11540 Sultan's Chandelier Burnside 引理 + DP

    题目传送门 https://vjudge.net/problem/UVA-11540 https://uva.onlinejudge.org/index.php?option=com_onlineju ...

  3. pspice介绍1(转载)

    PSpice的主要功能及特点: OrCAD软件的主要组成包括:OrCAD/Capture CIS.OrCAD/Layout Plus.OrCAD/Express及OrCAD/PSpice.它们分别是: ...

  4. Shell输入命令时一些有用的快捷键

    Ctrl + u: 从光标所在位置一直删除到开头 Ctrl + k: 从光标所在位置一直删除到尾 Ctrl + b: 光标向后移动一个字符 Ctrl + f: 光标后前移动一个字符 Alt + b: ...

  5. Linux系统重要文件

    Linux系统重要文件介绍与配置 一网卡配置文件 (一)网卡配置文件参数介绍 文件路径信息:/ec/sysconfig/network-scripts/ifcfg-eth0 文件作用说明:配置网卡地址 ...

  6. Redis5离线安装

    1. 直接上redis官网安装包, 然后上传服务器 https://redis.io/download 2. 解压 tar -zxvf redis-5.0.6.tar.gz 3. 进入redis根目标 ...

  7. sqlserver 中的时间算法

    DECLARE @Date DATETIME SET @Date=GETDATE() --前一天,给定日期的前一天 ,@Date) AS '前一天' --后一天,给定日期的后一天 ,@Date) AS ...

  8. node连接mysql数据库

    1. 创建项目,安装mysql 创建项目文件夹test, 在test文件夹下yarn add mysql --save安装mysql: 2. node使用mysql 在test文件夹下,创建test. ...

  9. paper 164: Siamese网络--相似度量方法

    简介:    Siamese网络是一种相似性度量方法,当类别数多,但每个类别的样本数量少的情况下可用于类别的识别.分类等.传统的用于区分的分类方法是需要确切的知道每个样本属于哪个类,需要针对每个样本有 ...

  10. 安装uWebSocketIO

    https://github.com/uNetworking/uWebSockets sudo apt-get install libuv1-dev git clone https://github. ...