题解 | #斐波那契数列#
斐波那契数列
https://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3
function Fibonacci(n) { if (n < 1 || n > 40) { return false; } let first = 1; let second = 1; let result = 0; if (n === 1 || n === 2) { return 1; } else { while (n > 2) { result = first + second; first = second; second = result; n--; } return result; } } module.exports = { Fibonacci: Fibonacci, };