728x90
프로그래머스 피보나치 수
간단한 피보나치 문제
n번 째 피보나치 수를 1234567로 나눈 수를 반환
func solution(_ n:Int) -> Int {
var F = [0, 1]
while F.count <= n {
F.append((F[F.endIndex - 2] + F.last!).quotientAndRemainder(dividingBy: 1234567).remainder)
}
return F[n]
}
// n return
// 3 2
// 5 5
728x90
'Algorithm' 카테고리의 다른 글
SwiftUI: 카펫 (0) | 2024.03.17 |
---|---|
SwiftUI: 짝지어 제거하기 (0) | 2024.03.16 |
SwiftUI: 다음 큰 숫자 (0) | 2024.03.14 |
SwiftUI: 이진 변환 반복하기 (0) | 2024.03.13 |
SwiftUI: 올바른 괄호 (0) | 2024.03.12 |