LeetCode练题——70. Climbing Stairs
2024-09-06 07:34:31
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))
最新文章
- Sybase PowerDesign 导入数据库结构formSqlserver
- 实用SQL
- jQuery: jquery.json.js
- Spring 一二事(5) - 依赖注入
- Spring mvc源码url路由-我们到底能走多远系列(38)
- POJ 1655 - Balancing Act 树型DP
- (Problem 17)Number letter counts
- iOS开发——点击图片全屏显示
- Python爬虫2----------运用代理访问
- vue路由详解
- ubuntu查看安装的pytorch/cuda版本
- python学习之旅(六)
- 树状DP HDU1520 Anniversary party
- Docker创建Tomcat镜像
- 小tips:JSON对象和字符串之间的相互转换JSON.stringify(obj)和JSON.parse(string)
- 上传头像,layui上传图片
- centos6下通用二进制安装mysql5.5.33
- IE8实现媒体查询
- 【bzoj1369】[Baltic2003]Gem 树形dp
- ZOJ1081:Points Within——题解