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.
1 parent 513070d commit 5484469Copy full SHA for 5484469
src/go/fibonacci_memoization.go
@@ -0,0 +1,26 @@
1
+package main
2
+
3
+import "fmt"
4
5
+var memo = make(map[int]int)
6
7
+func FibonacciMemoization(n int) int {
8
+ if n <= 1 {
9
+ return 1
10
+ }
11
12
+ // Check if the value is already memoized
13
+ if val, ok := memo[n]; ok {
14
+ return val
15
16
17
+ // Calculate Fibonacci recursively and store the result in memoization
18
+ result := FibonacciMemoization(n-1) + FibonacciMemoization(n-2)
19
+ memo[n] = result
20
+ return result
21
+}
22
23
+func main() {
24
+ n := 9
25
+ fmt.Println("Fibonacci Memoization:", FibonacciMemoization(n))
26
0 commit comments