Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c2eec66

Browse files
committed
--update: added fibonacci
1 parent 20280c8 commit c2eec66

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

‎src/_Classics_/fibonacci/index.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// the algorithm has time complexity of O(n^2), very bad!
2+
function fibonacci(position) {
3+
// if position is 1 or 2, the number in fibonacci sequence will be 1
4+
if (position < 3) {
5+
return 1;
6+
}
7+
// else the element in fibonacci sequence will be the sum of
8+
// element at position(p) (p -1) and (p - 2)
9+
return fibonacci(position - 2) + fibonacci(position - 1);
10+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /