You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
320 B
Go
19 lines
320 B
Go
package datastructures
|
|
|
|
// Factorial a function that computes the factorial or a number. Big (n) time and space complexity. For loop could use less memory.
|
|
func Factorial(n int) int {
|
|
if n < 1 {
|
|
return 1
|
|
}
|
|
|
|
return n * Factorial(n-1)
|
|
}
|
|
|
|
func Fib(n int) int {
|
|
if n < 1 {
|
|
return 1
|
|
}
|
|
|
|
return Fib(n-1) + Fib(n-2)
|
|
}
|