题解 | #斐波那契数列#
斐波那契数列
http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3
// 1 1 2 3 5 8
p q r
i=4
function Fibonacci(n)
{if(n == 1 || n == 2) return 1
if(n == 3) return 2
let p = 1, q = 1, r = 2
for(let i = 4; i <= n; i++){
p = q
q = r
r = p + q
}
return r
}
module.exports = {
Fibonacci : Fibonacci
};