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))

最新文章

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

热门文章

  1. 集成unittest做接口测试
  2. Python_函数进阶
  3. Git的基本使用 -- 远程仓库
  4. AcWing 913. 排队打水
  5. 1.5 面试问题整理:cl
  6. Java8 Time API与老Date之间的转换
  7. 爬虫(十一):selenium爬虫
  8. 搭建 Kubernetes 高可用集群
  9. bugku 白哥的鸽子
  10. shell批量创建数据表的一个方法