题解 | #斐波那契数列#
斐波那契数列
https://www.nowcoder.com/practice/aa8ffe28ec7c4050b2aa8bc9d26710e9
function fibonacci(n) {
if(n===0){
return 0;
}else if(n===1){
return 1
}
//0 1 1 2 3 5 8 13 21
let res=1,pr=1,temp;
while(n-->2){
temp=res;
res+=pr;
pr=temp
}
return res
}
查看16道真题和解析