[头条刷题] 斐波那切数列
int fib(const int num){
std::vector<int> fibs({0, 1});
if( num == 0 || num == 1){
return num;
}
else{
int len = fibs.size();
int elem = 0;
while( len - 1 < num){
int las_pos = len - 1;
int s_las_pos = las_pos - 1;
elem = fibs[s_las_pos] + fibs[las_pos];
fibs.push_back(elem);
len = fibs.size();
}
return elem;
}
}