The sword refers to Offer_Programming questions_7

Topic description

Everyone knows the Fibonacci sequence, and now you are asked to input an integer n, please output the nth item of the Fibonacci sequence.

n<=39

class Solution {
public:
    int Fibonacci(int n) {
        vector<int>vt;
        vt.push_back(0);
        vt.push_back(1);
        int i;
        for(i = 2; i <= n; i++) {
            vt.push_back(vt[i-1] + vt[i-2]);
        }
        return vt[n];
    }
};

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324739457&siteId=291194637