【LeetCode】70. Climbing Stairs 解题报告(Python)

70. Climbing Stairs [easy] (Python) 题目链接https://leetcode.com/problems/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 阅读详情

【LeetCode】70. Climbing Stairs 解题报告(Python)

题目地址:https://leetcode.com/problems/climbing-stairs/submissions/

题目描述

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.
4. 1 step + 1 step + 1 step
5. 1 step + 2 steps
6. 2 steps + 1 step

解法:动态规划

对于 n ( n > = 3 ) n(n>=3) n(n>=3)个台阶,可以先爬到第 n − 1 n-1 n−1个台阶,然后再爬一个台阶,或者先爬到 n − 2 n-2 n−2个台阶,然后爬两个台阶,因此有:
d p [ n ] = d p [ n − 2 ] + d p [ n − 1 ] dp[n] = dp[n-2] + dp[n-1] dp[n]=dp[n−2]+dp[n−1]

class Solution:
    def climbStairs(self, n: int) -> int:
        dp = [0 for i in range(n+1)]
        dp[0] = 1
        dp[1] = 1
        for i in range(2, n+1):
            dp[i] = dp[i-2] + dp[i-1]
        return dp[n]
LeetCode --- 70. Climbing Stairs解题报告 You are climbing a stair case. It takesnsteps 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:Givennwill be a positive... 阅读详情

相关推荐

为什么大语言模型推理要分成 Prefill 和 Decode?深入理解这两个阶段的真正意义

Prefill 阶段是语言模型推理中的第一个步骤,它负责处理你输入的所有上下文内容(prompt),为后续生成打下基础。“请解释一下 Transformer 的原理。这句话会被 tokenizer 编码为一串 token,比如["请", "解释", "一下", "Trans", "##former", "的", "原理", "。"]。然后这些 token 会进入 Transformer 模型进行前向传播。重点来了 👇。

Harry的博客 1万+

Leetcode 70. Climbing Stairs (python+cpp)

Leetcode 70. Climbing Stairs题目解析:动态规划 题目 解析:动态规划 这道题有很多的方法可以解,比如dfs+memorization,Fibonacci Number。但是这是最便于理解动态规划的一个题目,所以为了清晰这边只提供动态规划的解法。 动态规划的关键在于找到状态转移方程,通俗的说就是前一个状态到后一个状态怎么转移的。通过状态转移方程,我们可以通过最开始非常简单的状态(或者说是边界状态)一步步递推出复杂状态下的情况。所以重点在两部分:1. 边界状态的初始化 2. 状态转

qq_37821701的博客 404

解决Anaconda环境下catkin_make编译报错:Python路径冲突与empy模块缺失

本文详细分析了在Anaconda环境下使用catkin_make编译时出现的Python路径冲突与empy模块缺失问题,提供了快速解决方案和永久性环境配置方法。通过显式指定Python解释器路径或调整Anaconda配置,有效解决编译报错问题,适用于ROS开发与科学计算并行的场景。

weixin_28829629的博客 357

LeetCode 70 Climbing Stairs(Python详解及实现)

【题目】 You are climbing a stair case. It takes nsteps to reach to the top.   Each time you can either climb 1 or 2steps. In how many distinct ways can you climb to the top?   Note: Given n will be

toplatona 1964

AD9361 官方例程

文章目录一、官方资料1.1 介绍1.2 下载 和 使用1.3 相关资料二、步骤2.1 在Vivado中构建HDL2.2 在SDK中构建No- OS总结 一、官方资料 1.1 介绍 HDL参考设计介绍:AD9361 HDL Reference Designs 无操作系统介绍:AD9361 No-OS Software 1.2 下载 和 使用 HDL下载:Download HDL 在Vivado中构建HDL:Building HDL No-OS下载:Download No-OS 1.3 相关资料 AD

weixin_44630490的博客 3万+

王珊数据库系统概论第5版视频教材

目录 隐藏 说明:本课程共包括1种电子书、84个高清视频(共68课时)、1种纸质书(赠品)。 网授课程 王珊《数据库系统概论》(第5版)网授精讲班【共68课时】 序号 名称 课时 1 第1章 绪 论(1) 00:32:25 2 第1章 绪 论(2) 00:17:03 3 第1章 绪 论(3) 00:50:19 4 第1章 绪 论(4) 00:20:37 5 第1章 绪 论(5) 00:24:47 6 第2章 关系数据库(1) 00:47:23 7 第2章 关系数据库(2) 00:14:48 8 第2章 关系

mrtaoy96的博客 1156

LeetCode之70. Climbing Stairs python

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

新雪兰 278

从理论到实践:Zemax驱动下的离轴三反光学系统全流程构建

本文详细阐述了从理论推导到软件实现的离轴三反光学系统全流程设计方法。文章首先分析了离轴三反系统在空间遥感等领域的优势,然后手把手指导如何基于像差理论计算共轴三反的初始结构参数,包括曲率半径与圆锥系数。最后,重点介绍了在Zemax中完成从共轴建模、视场离轴设置到优化与性能评估的完整实战步骤,为光学工程师提供了宝贵的经验与避坑指南。

weixin_29205061的博客 251

[leetcode] 70. Climbing Stairs @ python

原题 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 positiv...

闲庭信步 261

YOLOv11的元学习(MAML)few-shot适配-(5样本内快速适应新类别)

本文提出了一种基于元学习和YOLOv11的少样本目标检测方法。首先介绍了元学习的核心概念和MAML算法原理,分析了YOLOv11的架构改进及其在少样本检测中的适用性。针对少样本检测面临的过拟合、特征混淆和定位困难等挑战,提出了基于MAML的解决方案。在实现方面,详细阐述了环境配置、数据预处理和任务采样策略,构建了支持N-way K-shot任务的数据加载器。实验表明,该方法相比传统微调策略可显著提升小样本场景下的检测性能。

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 615

[STM32F103C8T6]W5500+Modbus TCP(HAL库)

本章节是博主学习Modbus TCP所写的一篇文章Modbus TCP是Modbus的一个分支,主要用到网口通信的,在工业上也用的很频繁,我们公司最近的项目就是用的W5500+modbus TCP来和PC端的上位机通信和交互的。虽然这个项目不是我在写代码,但是我都学了Modbus RTU了,那我也抽空学习一下Modbus TCP吧。本次的Modbus TCP不是博主写的,是一个大佬开源的一个W5500写的一个Mobus TCP代码,我在这个基础上自己写了主机读从机多个数据,和主机写从机寄存器的函数。

sinat_58149788的博客 4093

LeetCode 70. Climbing Stairs (Python)

题目描述: 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 positi

Lu_gee的博客 784

ARM6818嵌入式视频播放器:硬解加速与Framebuffer渲染实战

嵌入式Linux音视频系统是智能座舱、工业HMI等场景的核心能力,其本质是软硬协同的实时多媒体处理系统。原理上需打通内核驱动(如VPU硬件编解码、FIMD多图层合成)、用户空间框架(GStreamer pipeline定制、SDL2硬件渲染)与应用层同步机制(PTS/HTS双时钟校准)。技术价值在于显著降低CPU负载(硬解可压至15%以下)、提升启动速度(<1.2s首帧)并保障音画同步精度(±3ms级)。典型应用场景包括车载信息娱乐、边缘AI终端及无X11的工控显示设备。本文基于ARM6818平台,深入VP

weixin_32456485的博客 81

【LeetCode】70. Climbing Stairs 解题报告(Java & Python)

Climbing Stairs[LeetCode]https://leetcode.com/problems/climbing-stairs/Total Accepted: 106510 Total Submissions: 290041 Difficulty: EasyQuestion You are climbing a stair case. It takes n steps to rea

负雪明烛 2368

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

leetcode python3 简单题70. Climbing Stairs

1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第七十题 (1)题目 英文: 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 d...

从此做一个俗人 256

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

[勇者闯LeetCode] 70. Climbing Stairs

[勇者闯LeetCode] 70. Climbing StairsDescription 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 c

fanguzhai的博客 476

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

LeetCode 70. 爬楼梯(Climbing Stairs)

该题是斐波那契数列变种动态规划的基础题目,经典入门题可作为多种动态规划变体问题(如跳台阶、解码方法、打家劫舍等)的基础。

2501_91641025的博客 593

【每日一题leetcode】70 Climbing Stairs

这道题花了蛮久时间,刚开始接触DP,需要多一些思维训练。 题目: **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 t...

github_39395521的博客 752

[LeetCode]70. Climbing Stairs ★

每天一道编程题题目描述样例python解法C语言解法 题目描述 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? No...

xingyu97的博客 202

leetcode 70. Climbing Stairs(python)

描述 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: T

王大呀呀的博客 336

LeetCode-70 Climbing Stairs

Description 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? Constraints: 1 <= n <= 45 Example Example 1: Input: 2 Output: 2 Explanat

秦智慧的博客 179

leetcode 70. Climbing Stairs 动态规划 python3

一.问题描述 You are climbing a stair case. It takesnsteps 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:Givennwill be a ...

CSerwangjun的博客 380

MCP 2026-07-28 规范深度解读:无状态传输层、扩展框架与弃用策略(mcp-for-beginners)

MCP(Model Context Protocol)`2026-07-28` 版本是该协议自发布以来最大的一次修订:六个 Specification Enhancement Proposals(SEP)将协议核心改为无状态、让扩展成为一等公民,并在一套新的功能生命周期政策下正式弃用 Roots、Sampling 与 Logging。本文以 mcp-for-beginners 课程中的 [01-C

gitblog_00525的博客 397

【LeetCode】70. Climbing Stairs python3解法

题目描述: 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 posi...

weixin_44540204的博客 296

【Leetcode】70. Climbing Stairs

经典的爬楼梯问题 方法1 DP dp法,经典dp,注意初始值即可。 dp法是一种from bottom to top 的方法 class Solution1: def climbStairs(self, n): """ :type n: int :rtype: int """ if n == 1: ...

很吵请安静 233
上一篇: 【LeetCode】62. Unique Paths 解题报告(Python)
下一篇: 【LeetCode】121. Best Time to Buy and Sell Stock 解题报告(Python)
ttinch
博客等级 码龄7年 0粉丝 19原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值