和斐波拉契很像,有数学递推出来是[1,2,3,5,9,...,f(n-1)+f(n-2)],后面是前面两个数之和。可以通过列表来求,将每次的加入append输入,然后索引出来。

# -*- coding:utf-8 -*-
class Solution:
    def jumpFloor(self, number):
        # write code here
        a = [1,2]
        for i in range(number-2):
            a.append(a[i]+a[i+1])
        return a[number-1]