aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--70-go/go.mod3
-rw-r--r--70-go/main.go30
2 files changed, 33 insertions, 0 deletions
diff --git a/70-go/go.mod b/70-go/go.mod
new file mode 100644
index 0000000..a3df715
--- /dev/null
+++ b/70-go/go.mod
@@ -0,0 +1,3 @@
+module 70
+
+go 1.19
diff --git a/70-go/main.go b/70-go/main.go
new file mode 100644
index 0000000..0613cfe
--- /dev/null
+++ b/70-go/main.go
@@ -0,0 +1,30 @@
+package main
+
+import "fmt"
+
+func climbStairs(n int) int {
+ var fact func(n int, memo map[int]int) int
+
+ memo := make(map[int]int, n)
+ fact = func(n int, memo map[int]int) int {
+ if _, ok := memo[n]; ok {
+ return memo[n]
+ }
+ if n < 2 {
+ return 1
+ }
+
+ memo[n] = fact(n-1, memo) + fact(n-2, memo)
+ return memo[n]
+ }
+
+ return fact(n, memo)
+}
+
+func main() {
+ fmt.Println(climbStairs(2))
+ fmt.Println(climbStairs(3))
+ fmt.Println(climbStairs(4))
+ fmt.Println(climbStairs(5))
+ fmt.Println(climbStairs(44))
+}