We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项。斐波那契数列的定义如下:
n
F(0) = 0, F(1) = 1 F(N) = F(N - 1) + F(N - 2), 其中 N > 1.
斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得出。
示例 1:
输入:n = 2 输出:1
示例 2:
输入:n = 5 输出:5
/** * @param {number} n * @return {number} */ var fib = function(n) { if(n<=1){ return n; } let first = 0; let second = 1; for(let i = 0;i<n-1;i++){ let sum = (first + second); first = second; second = sum; } return second;//此时second就等于sum };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
斐波那契数列
一、题目描述
写一个函数,输入
n
,求斐波那契(Fibonacci)数列的第n
项。斐波那契数列的定义如下:斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得出。
示例 1:
示例 2:
二、解题思路
三、代码实现
The text was updated successfully, but these errors were encountered: