class Solution {
public:
int Fibonacci(int n) {
int res[2] = {0,1};
if(n<=1)
return res[n];
int num1 = 1;
int num2 = 0;
int sum = 0;
for(int i = 2;i<=n;i++)
{
sum = num1+num2;
num2 = num1;
num1 = sum;
}
return sum;
}
};
斐波那契数列非递归算法
最新推荐文章于 2020-08-01 17:25:53 发布