import Foundation
func solution(_ answers: [Int]) -> [Int] {
let a = [1, 2, 3, 4, 5]
let b = [2, 1, 2, 3, 2, 4, 2, 5]
let c = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
var array = [0, 0, 0]
var result = [Int]()
for i in 0..<answers.count {
if a[i % 5] == answers[i] { array[0] += 1 }
if b[i % 8] == answers[i] { array[1] += 1 }
if c[i % 10] == answers[i] { array[2] += 1}
}
for i in 0..<array.count {
if array[i] == array.max() {
result.append(i + 1)
}
}
return result
}
'코딩테스트 > Swift' 카테고리의 다른 글
[Swift] 백준 1406 에디터 - 시간복잡도에 익숙해지자 (0) | 2022.08.09 |
---|---|
[Swift] 프로그래머스 행렬 테두리 회전하기 (0) | 2022.03.27 |
[Swift]프로그래머스 K번째 수 (0) | 2021.09.21 |
[Swift]프로그래머스 기능개발 (0) | 2021.09.21 |
[Swift] 백준 2751 수 정렬하기 2 (0) | 2021.09.05 |