//
#include "stdafx.h"
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
int Fibonacci(int n) {
if (n <= 0)
{
return 0;
}
if (n == 1)
{
return 1;
}
else
{
int num1 = 0;
int num2 = 1;
int num3 = 0;
for (int i = 2; i <= n; i++)
{
num3 = num1 + num2;
num1 = num2;
num2 = num3;
}
return num3;
}
}
};
int main()
{
int abc;
cin >> abc;
Solution test;
cout<<test.Fibonacci(abc);
return 0;
}
剑指offer 07 斐波那契数列
最新推荐文章于 2021-01-30 14:35:53 发布