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

更高效的算法 #1022

Open
hurricane-gathering opened this issue Nov 24, 2020 · 0 comments
Open

更高效的算法 #1022

hurricane-gathering opened this issue Nov 24, 2020 · 0 comments

Comments

@hurricane-gathering
Copy link

int fib(int n) { // 迭代版
int f = 1, g = 0; // 初始化 fib(-1),fib(0)
while (0 < n--) {
g += f;
f = g - f; // 依据原始定义,通过 n 次加法和减法计算 fib(n)
}
return g;
}

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

2 participants
@hurricane-gathering and others