2. The sword refers to Offer 10- I. Fibonacci sequence (C++)

Link: Snap

Method: use recursion

Then look at the code

class Solution {
public:
    int fib(int n) {
        int mod = 1000000007;
        if(n<2)
        {
            return n;
        }
        else{
            return ((fib(n-1)+fib(n-2))%mod);
        }
    }
};

In the end, it can run through half of the use cases, because the complexity of recursion is high. 

Guess you like

Origin blog.csdn.net/qq_59392324/article/details/122529454