极客时间返利平台,你可以在上边通过山月的链接购买课程,并添加我的微信 (shanyue94) 领取返现。

# 请输出 100 以内的菲波那切数列

Issue

欢迎在 Gtihub Issue 中回答此问题: Issue 653 (opens new window)

function fib(n) {
  let a = 0,
    b = 1;
  let r = [0];
  while (b < n) {
    r.push(b);
    [a, b] = [b, a + b];
  }
  return r;
}
function Fibonacci(n, ac1 = 1, ac2 = 1, arr = [0]) {
  if (n <= ac2) {
    return arr;
  }
  arr.push(ac2);
  return Fibonacci(n, ac2, ac1 + ac2, arr);
}
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;
}

function fib(n, fib1 = 1, fib2 = 1, result = []) { if(n <= fib1){ return result } result.push(fib1) return fib(n, fib2, fib1 + fib2, result) }

Last Updated: 6/26/2022, 10:48:10 AM