问题:

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 思路:
上台阶问题,一次只能上一个或两个台阶,问总共有n个台阶,一共有多少种走法。
明显的动态规划问题,
当要到达地n个台阶的时候,有两种走法,第一种是从N-1个台阶走一步,第二种是N-2个台阶走两步。
class Solution:
def climbStairs(self, n: int) -> int:
if n ==1 :return 1
count= [0 for i in range(n)]
count[0] = 1
count[1] = 2
for i in range(2,n):
count[i] = count [i-1] + count[i-2]
return count[n-1]

Python3解leetcode Maximum SubarrayClimbing Stairs的更多相关文章

  1. Python3解leetcode Maximum SubarrayHouse Robber

    问题描述: You are a professional robber planning to rob houses along a street. Each house has a certain ...

  2. Python3解leetcode Maximum Subarray

    问题描述: Given an integer array nums, find the contiguous subarray (containing at least one number) whi ...

  3. Python3解leetcode Min Cost Climbing Stairs

    问题描述: On a staircase, the i-th step has some non-negative cost cost[i]assigned (0 indexed). Once you ...

  4. Python3解leetcode Best Time to Buy and Sell Stock II

    问题描述: Say you have an array for which the ith element is the price of a given stock on day i. Design ...

  5. Python3解leetcode N-ary Tree Level Order Traversal

    问题描述: Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to ...

  6. Python3解leetcode Rotate Array

    问题描述: Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: ...

  7. Python3解leetcode Linked List Cycle

    问题描述: Given a linked list, determine if it has a cycle in it. To represent a cycle in the given link ...

  8. Python3解leetcode Single Number

    问题描述: Given a non-empty array of integers, every element appears twice except for one. Find that sin ...

  9. Python3解leetcode Same TreeBinary Tree Level Order Traversal II

    问题描述: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, fro ...

随机推荐

  1. 【GoldenGate】使用OGG,两个Oracle库之间单向同步数据

    ************************************************************************ ****原文:blog.csdn.net/clark_ ...

  2. API -- 图书

    豆瓣IAPI:https://developers.douban.com/wiki/?title=book_v2#get_isbn_book 其他:http://www.cnblogs.com/sop ...

  3. React常用方法手记

    1.Reactjs 如何获取子组件的key值?请问antd中table自定义列render方法怎么获取当前第几列? https://segmentfault.com/q/101000000453235 ...

  4. nexus搭建maven私服及私服jar包上传和下载

    nexus搭建maven私服及私服jar包上传和下载 标签: nexus管理maven库snapshot 2017-06-28 13:02 844人阅读 评论(0) 收藏 举报 分类: Maven(1 ...

  5. C#的默认访问权限(转)

    1.在namespace中的类.接口默认是internal类型的,也可以显示的定义为public类型,不允许是其他访问类型.2.在一个类里面,属性和方法默认是private的,可以显示的定义为publ ...

  6. 我的Java开发学习之旅------>解惑Java进行三目运算时的自动类型转换

    今天看到两个面试题,居然都做错了.通过这两个面试题,也加深对三目运算是的自动类型转换的理解. 题目1.以下代码输出结果是(). public class Test { public static vo ...

  7. 【Xcode学C-4】进制知识、位运算符、变量存储细节以及指针的知识点介绍

    一.进制知识 (1)默认是十进制.八进制前面加0.即int num1=015;是13.十六进制前面加0x/0X.即int num1=0xd.结果是13.二进制前面是0b/0B,即int num1=0b ...

  8. (Android)react-native-splash-screen实践-解决react-native打包好后启动白屏的问题

    1.安装 npm i react-native-splash-screen --save or yarn add react-native-splash-screen --save 2.自动配置 re ...

  9. gon

    gem 'gon' application.html 中添加 =include_gon action中 gon.activities = @activities js中 gon.activities

  10. 2016WWDC详解

    今年苹果WWDC 2016上把所有系统都更新了个遍,watchOS.tvOS.macOS 和 iOS 都或多或少带来了新功能. 本文的主角是更新最多的 iOS 10,第一时间在一部 iPhone 6s ...