js 斐波那契数列实现

 1.递归
1
2
3
4
5
6
7
8
function fib(n){
    if(n==1||n==2){
        return 1;
    }
    return fbnq(n-1)+fbnq(n-2);
}
fbnq(10);
//55

时间复杂度为O(2^n),空间复杂度为O(n)

 
    }
    return res;
}
fb(10);
原文地址:https://www.cnblogs.com/xiaobai110/p/6654606.html