leetcode - 509. 斐波那契数
题目
代码
#include <iostream>
#include <vector>
using namespace std;
int fib(int n) {
if(n < 2){
return n;
}
vector<int> F(n+1);
F[0] = 0;
F[1] = 1;
for(int i = 2; i <= n; i++){
F[i] = F[i-1] + F[i-2];
}
return F[n];
}
int main(){
int n, res;
cin>>n;
res = fib(n);
cout<<res;
return 0;
}