该方法作为一种演示功能左右,运行较慢. #include <iostream> using namespace std; class Fibonacci{ public: int a, b, c; void generate(int); }; void Fibonacci::generate(int n){ a = ; b = ; cout << a << " " <<b; ; i<= n-; i++){ c = a + b; co…
斐波拉契数列是指这样一个数列: F(1)=1; F(2)=1; F(n)=F(n-1)+F(n); public class Solution { public int Fibonacci(int n) { int preNum = 1; int prePreNum = 0; int result = 0; if(n ==0){ return 0; } if(n == 1){ return 1; } for(int i = 2; i <= n; i ++){ result = preNum +…