2019-06-03剑指 跳台阶

class Solution:
    def jumpFloor(self, number):
        # write code here
        def dfs(n):
            res=0
            if rec[n]!=-1:
                return rec[n]
            elif n==1:res= 1
            elif n==2:res= 2
            else:
                res= dfs(n-1)+dfs(n-2)
            rec[n]=res
            return res

        rec=[-1 for i in range(number+1)]
        return dfs(number)

你可能感兴趣的:(2019-06-03剑指 跳台阶)