请输出 100 以内的菲波那切数列
Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 653
Author 回答者: shfshanyue
function fib(n) {
let a = 0,
b = 1;
let r = [0];
while (b < n) {
r.push(b);
[a, b] = [b, a + b];
}
return r;
}
Author 回答者: heretic-G
function Fibonacci(n, ac1 = 1, ac2 = 1, arr = [0]) {
if (n <= ac2) {
return arr;
}
arr.push(ac2);
return Fibonacci(n, ac2, ac1 + ac2, arr);
}
Author 回答者: haotie1990
function fibonacciDp(n) {
const f = [];
f[0] = 0;
f[1] = 1;
for (let i = 2; i < n; i++) {
f[i] = f[i - 1] + f[i - 2];
}
return f;
}
Author 回答者: Jie-echo
function fib(n, fib1 = 1, fib2 = 1, result = []) { if(n <= fib1){ return result } result.push(fib1) return fib(n, fib2, fib1 + fib2, result) }