Skip to content
New issue

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

尾递归(斐波那契数列) #130

Open
Sunny-117 opened this issue Nov 3, 2022 · 3 comments
Open

尾递归(斐波那契数列) #130

Sunny-117 opened this issue Nov 3, 2022 · 3 comments

Comments

@Sunny-117
Copy link
Owner

No description provided.

@weirong111
Copy link

function Fibonacci(n,num=1,sum=1){

    if (n<=2){
        return sum;
    }
    return Fibonacci(n-1,sum,num+sum);
}

@weirong111
Copy link

function feibo3(n) {
  let pre = 1;
  let cur = 1;
  for (let i = 2; i <= n; i++) {
    [pre, cur] = [cur, cur + pre];
  }
  return cur;
}

@fantasticbin
Copy link

function fibonacci(n) {
    if (n <= 2) {
        return n;
    }

    return fibonacci(n - 1) + fibonacci(n - 2);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants