问题描述
https://www.lintcode.com/problem/fibonacci/description?_from=ladder&&fromId=6
const fibonacci = function (n) {
let arr = [];
let i = 0;//循环次数
let j = 0;//加数
let k = 1;//加数
//得出整条n的斐波那契数列
while(i < n){
let tmp = 0;
i++;
arr.push(j);
tmp = k;
k += j;
j = tmp;
}
return arr[n-1];
}
我的缺点1:过分追求细节化
const fibonacci = function (n) {
// let arr = [];
let i = 0;//循环次数
let j = 0;//加数
let k = 1;//加数
//得出整条n的斐波那契数列
while(i < n-1){
let tmp = 0;
i++;
// arr.push(j);
tmp = k;
k += j;
j = tmp;
}
return j;
}
网友评论