// 方式一
let fibnacci = n => n <=0 ? 0 : n ==1 ? 1 : fibnacci(n -2) + fibnacci(n -1);
//时间复杂度 O(logn)

// 方式二 let fib = n => { if(n==0){ return 0; } let a1 = 0,a2=1; for(let i = 1; i < n;i++){ [a1,a2] = [a2,a1+a2] } return a2; }
// 时间复杂度O(n)

// 方式三

   let fib = n => (Math.pow((1 + Math.sqrt(5))/2,n) - Math.pow((1 - Math.sqrt(5))/2,n)) / Math.sqrt(5);

 

 

相关文章:

  • 2021-10-10
  • 2021-06-09
  • 2022-02-15
  • 2021-10-16
  • 2022-03-08
  • 2021-09-04
猜你喜欢
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2021-12-15
  • 2021-10-02
  • 2022-01-21
相关资源
相似解决方案