问题:

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. 【C/C++】高亮C++中函数的重写——函数名相同?参数列表相同?返回值相同?

    C++的重载给人留下了非常深刻的影响,原因是重载的条件很值得注意:函数名相同,参数列表不相同的两个函数构成重载函数,而无关乎二者的返回值. 但是C++中的函数重写又是另一码事.标准规定:只要函数名相同 ...

  2. Spark源码分析之七:Task运行(一)

    在Task调度相关的两篇文章<Spark源码分析之五:Task调度(一)>与<Spark源码分析之六:Task调度(二)>中,我们大致了解了Task调度相关的主要逻辑,并且在T ...

  3. JavaScript读书笔记(6)-Function

    Function类型 ECMAScript中函数是对象,每个函数都是Function类型的实例,也有属性和方法,函数是对象,函数名实际上市一个指向函数对象的指针,不会与某个函数绑定: function ...

  4. redis错误error记录

    早上登服务器,看到程序的redis的报错, 具体如下: (error) MISCONF Redis is configured to save RDB snapshots, but is curren ...

  5. pooler [转]

    pooler和poolboy都是用erlang写的管理进程池的库. pooler/poolboygithub : seth/pooler · GitHubgithub : devinus/poolbo ...

  6. vue 流程设计器

    github地址:https://github.com/280780363/gucflow.designer demo地址:https://280780363.github.io/gucflow.de ...

  7. HTML5画布(基础篇11-10)

    <script type="text/javascript"> $(function(){ var s = $("#myCanvas")[0]; v ...

  8. maven 配置: 修改默认的 .m2仓库 默认存储路径.

    maven 配置: 修改默认的 .m2仓库 默认存储路径. 一 .在系统maven里修改 1.在maven_HOME/conf/下找到配置文档 settings.xml 在文档中添加如下的配置说明 & ...

  9. 我的Android进阶之旅------>Ubuntu下不能识别Android设备的解决方法

    Bus 001 Device 006: ID 1b20:0c81 MStar Semiconductor, Inc.      今天不知道Ubuntu发了什么疯,昨天还用的好好的,今天就突然不能识别我 ...

  10. js添加方法和邦定事件

    function(obj,objArr){ if(($(obj).attr("type") == "checkbox" && $j(obj).p ...