标签:leetcode style range cal else weight alc pre cli
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
self.memo = [-1 for i in range(n+1)]
return self.calcWays1(n)
def calcWays1(self,n):
if n == 1:
return 1
if n == 2:
return 2
else:
return self.climbStairs(n-1) + self.climbStairs(n-2)
def calcWays2(self, n):
if n == 0 or n == 1:
return 1
if self.memo[n] == -1:
self.memo[n] = self.calcWays2(n-1) + self.calcWays2(n-2)
def calcWays3(self, n):
memo = [-1 for i in range(n+1)]
memo[1] = 1
memo[2] = 2
for i in range(3,n+1):
memo[i] = memo[i-1] + memo[i-2]
return memo[n]
标签:leetcode style range cal else weight alc pre cli
原文地址:https://www.cnblogs.com/lux-ace/p/10546417.html