爬楼梯

你在爬楼梯,需要n步才能爬到楼梯顶部
每次你只能向上爬1步或者2步。有多少种方法可以爬到楼梯顶部?

 https://www.nowcoder.com/practice/d679cfa563974385a3bef8cd854c73db?tpId=46&&tqId=29108&rp=1&ru=/ta/leetcode&qru=/ta/leetcode/question-ranking

#
# 
# @param n int整型 
# @return int整型
#
class Solution:
    def climbStairs(self , n ):
        # write code here
        dp=[0,1,2]
        for i in range(3,n+1):
            dp.append(dp[i-1]+dp[i-2])#把所有结果保存在一个数组中
        return dp[n]

  每一层的方法,就是前一层+前两层的方法!

原文地址:https://www.cnblogs.com/zmh-980509/p/13545421.html