首页 > 技术文章 > 21. 斐波那契数列

make-big-money 2020-02-25 23:57 原文

 

 

class Solution {
public:
    int Fibonacci(int n) {
        int f=0,g=1;
        while(n--)
        {
            f=f+g;
            int temp = g;
            g=f;
            f = temp;
        }
        return f;
    }
};

 

 

 

 

9这题用递归会溢出

 

推荐阅读