func solution(_ cacheSize:Int, _ cities:[String]) -> Int {
var time = 0
var cache = [String]()
var cities = cities.map { $0.lowercased() }
for city in cities {
if cache.contains(city) {
time += 1
cache.remove(at: cache.firstIndex(of: city)!)
cache.append(city)
} else {
time += 5
cache.append(city)
if cache.count > cacheSize {
cache.removeFirst()
}
}
}
return time
}'프로그래머스 > Lv.2' 카테고리의 다른 글
| [Swift] 뉴스 클러스터링 (0) | 2023.02.04 |
|---|---|
| [Swift] 기능개발 (0) | 2023.02.04 |
| [Swift] 괄호 회전하기 (0) | 2023.02.04 |
| [Swift] 가장 큰 수 (0) | 2023.02.04 |
| [Swift] 압축 (0) | 2023.02.04 |