new file: algo/fibonacci.go
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
|
||||
- [x] Kadane's Algorithm
|
||||
- [x] Euclidean gcd
|
||||
- [ ] Fibonacci
|
||||
- [x] Fibonacci
|
||||
- [ ] Modular Arithmetic
|
||||
- [ ] Sieve of Eratosthenes
|
||||
- [ ] BFS Breadth-First Search
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package algo
|
||||
|
||||
// Fib() -> fibonacci linear implementation O(n)
|
||||
func Fib(target int) int {
|
||||
a := 0
|
||||
b := 1
|
||||
|
||||
if target <= 1 {
|
||||
return target
|
||||
}
|
||||
|
||||
for a < target {
|
||||
a, b = b, a+b
|
||||
}
|
||||
return a
|
||||
}
|
||||
Reference in New Issue
Block a user