Last active: 2 years ago
func fibonacci22(n int) int {
f := make([]int, n+1, n+2)
if n < 2 {
f = f[0:2]
}
f[0] = 0
f[1] = 1
for i := 2; i <= n; i++ {
f[i] = f[i-1] + f[i-2]
}
return f[n]
}
func fibonacci2(n int) int {
x, y := 0, 1
for i := 2; i <= n; i++ {
x, y = y, x+y
}
return y
}
func fibo2(n int) int {
if n < 2 {
return n
}
return fibo2(n-1) + fibo2(n-2)
}