LeetCode练题——70. Climbing Stairs
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 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的更多相关文章
- 刷题70. Climbing Stairs
一.题目说明 题目70. Climbing Stairs,爬台阶(楼梯),一次可以爬1.2个台阶,n层的台阶有几种爬法.难度是Easy! 二.我的解答 类似的题目做过,问题就变得非常简单.首先用递归方 ...
- [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 ...
- 【leetcode❤python】70. Climbing Stairs
#Method1:动态规划##当有n个台阶时,可供选择的走法可以分两类:###1,先跨一阶再跨完剩下n-1阶:###2,先跨2阶再跨完剩下n-2阶.###所以n阶的不同走法的数目是n-1阶和n-2阶的 ...
- [刷题] 70 Climbing Stairs
要求 楼梯共有n个台阶,每次上一个台阶或两个台阶,一共有多少种上楼梯的方法? 示例 输入:n=3 [1,1,1],[1,2,],[2,1] 输出:n=3 实现 自顶向下(递归) 递归 1 class ...
- Leetcode之70. Climbing Stairs Easy
Leetcode 70 Climbing Stairs Easy https://leetcode.com/problems/climbing-stairs/ You are climbing a s ...
- [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 ...
- 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 解 ...
- 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 ...
随机推荐
- mysql查询速度慢的分析和解决
一.定位执行慢的sql,如2秒内没执行完的抽取出来 show engines;查看慢查询时间show variables like 'slow%';查看设置多久是慢查询show variables l ...
- .net_DevExpress控件使用经验总结
(转)DevExpress控件使用经验总结DevExpress是一个比较有名的界面控件套件,提供了一系列的界面控件套件的DotNet界面控件.本文主要介绍我在使用DevExpress控件过程中,遇到或 ...
- MySql -- primary key主键约束
4.primary key主键约束 在一张表中: 1) 主键约束是 NOT NULL.UNIQUE唯一的记录. 2) 主键约束必须是唯一的值. 3) 主键约束列不能包含 NULL 值. 注意:每个表都 ...
- SSH通道 Xshell
SSH是每一台Linux电脑的标准配置. SSH是一种网络协议,用于计算机之间的加密登录(安全的). 1. 登录远程主机 $ ssh user@host 2. SSH的默认端口是22, ...
- c++primer练习题
2.7 输出地址和姓名(1 #include <iostream> using namespace std; int main() { int 距离; cout << &quo ...
- 哥廷根: Heroes in My Heart
哥廷根: Heroes in My Heart (本篇的文字部分均出自北大未名BBS的连载 Heroes in my heart 中哥廷根的部分,作者 ukim. 话说,有任何人能够联系上 ukim ...
- go基础_定时器
每间隔5s打印一句hello // time_ticker package main import ( "fmt" "time" ) func main() { ...
- linux mv命令 cp命令
mv mv [options] source dest -f : 在mv操作要覆盖某已有的目标文件时不给任何指示 命令格式 运行结果 mv 文件名 文件名 将源文件名改为目标文件名 mv 文件名 目录 ...
- 动态调整线程数的python爬虫代码分享
这几天在忙一个爬虫程序,一直在改进他,从一开始的单线程,好几秒一张图片(网络不好),,,到现在每秒钟十几张图片,,, 四个小时586万条数据,,,简直不要太爽 先上图 最终写出来的程序,线程数已经可以 ...
- [lua]紫猫lua教程-命令宝典-L1-01-03. 数值数据
lua5.3在线手册地址 https://cloudwu.github.io/lua53doc/contents.html#contents 其实我们直接啃手册就够了 推荐如果有基础的先啃手册再看紫 ...