func fibonacciNumbers(n int) int {
//기저조건
if n <= 1 {
return 1
} else {
return fibonacciNumbers(n-1) + fibonacciNumbers(n-2)
}
}
// 피보나치 수열 항의 나열
func fibonacciNumbers2(n int) []int {
result := []int{0, 1}
for i := 0; i <= n; i++ {
temp := result[len(result)-1] + result[len(result)-2]
if temp > n {
break
}
result = append(result, temp)
}
return result
}
'Web Development > CommonSense' 카테고리의 다른 글
JWT TOKEN 저장 위치 비교 (2) | 2023.05.28 |
---|---|
[AL&DS] 팩토리얼 (0) | 2022.11.12 |
[AL&DS] 큐 (0) | 2022.11.12 |
[AL&DS] 스택 (0) | 2022.11.12 |
[AL&DS] 삽입정렬 (0) | 2022.11.12 |