We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 20280c8 commit c2eec66Copy full SHA for c2eec66
src/_Classics_/fibonacci/index.js
@@ -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