We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3e965e7 + bb5377a commit 0197303Copy full SHA for 0197303
src/cpp/FibonacciMemoization.cpp
@@ -0,0 +1,28 @@
1
+#include <iostream>
2
+#include <vector>
3
+
4
+using namespace std;
5
6
+vector<int> memo;
7
8
+int fibonacciMemoization(int n) {
9
+ if (n <= 1) {
10
+ return n;
11
+ }
12
+ if (memo[n] != -1) {
13
+ return memo[n];
14
15
16
+ memo[n] = fibonacciMemoization(n - 1) + fibonacciMemoization(n - 2);
17
18
+}
19
20
+int main() {
21
+ int test_nbr = 12;
22
23
+ // Initialize the memoization table with -1 (uncomputed)
24
+ memo.assign(test_nbr + 1, -1);
25
26
+ cout << "memoization: " << fibonacciMemoization(test_nbr) << endl;
27
+ return 0;
28
0 commit comments