剑指 Offer 10-I 斐波那契数列

标签: 剑指 Offer 发布于:2021-11-24 21:12:08 编辑于:2021-11-24 21:32:35 浏览量:965

概述

https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/

直接法

class Solution {
public:
    int store[101] = {0};
    int fib(int n) {
        if (n == 0) return 0;
        if (n == 1) return 1;
        if (store[n] != 0) return store[n] % 1000000007;
        store[n] = fib(n-1) + fib(n-2);
        return store[n] % 1000000007;
    }
};

未经允许,禁止转载,本文源站链接:https://iamazing.cn/