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 ...
随机推荐
- Idea实用小Tips
设置keymap 自己根据习惯选择keymap(键位) 插件安装 ###省去set.get方法以及基于注解的日志框架 lombok plugin ###找bug用的 FindBugs-IDEA ### ...
- django入门与实践(续)
完善博客 博客页面设计 页面概要 1.博客主页面 主页面内容 文章标题列表,超链接 发表博客按钮(超链接) 列表编写思路 取出数据库中所有文章对象 将文章对象们打包成列表,传递到前端 前端页面把文章以 ...
- can总线中什么是远程帧
所谓“远程帧”是一个传统翻译上的误区.Remote Frame实际上它的意义是“遥控帧”,发起方发起特定ID的远程帧,并且只发送ID部分,那么与其ID相符的终端设备就有义务在后半段的数据部分接管总线控 ...
- shiro登录认证过程讲解
先粘出登录的代码 1. 可以看到已经获取到了username和password ,为了接下来的认证过程,我们需要获取subject对象,也就是代表当前登录用户,并且要将username和passw ...
- echarts相关问题记录
1.图标距离容器边界 //echats options options : { //... grid : { top : 40, //距离容器上边界40像素 bottom: 30 //距离容器下边界3 ...
- linux中卸载mysql以及安装yum
卸载mysql:https://blog.csdn.net/qq_41829904/article/details/92966943 链接2:https://www.cnblogs.com/nickn ...
- Go同步等待组/互斥锁/读写锁
1. 临界资源 package main import ( "fmt" "time" ) func main() { /* 临界资源: */ a := 1 go ...
- ftrace使用
前段时间遇到个问题,有个后继音频数据处理线程调度不及时导致音频输出延迟,音视频不同步. 因此从系统上入手,采用ftrace进行debug,来看有哪些线程会去抢占音频数据处理线程. ftrace 提供了 ...
- html - html5 audio 音乐自动播放,循环播放等
转自:http://blog.csdn.net/u012246458/article/details/50618759 audio播放音乐 <audio id="audio" ...
- 68 for循环2 for循环最简单的用法
#include <stdio.h> int main (void) { int i ; ; ; i<; i+=) //i+=2 等价于 i= i+2: { sum = sum + ...