[Swift] 캐시 | 프로그래머스
2021. 10. 7. 10:13
Algorithm
https://programmers.co.kr/learn/courses/30/lessons/17680 Int { if cacheSize == 0 { return cities.count * 5 } var lru: [String] = [] var answer = 0 for city in cities.map{$0.uppercased()} { if(lru.contains(city)) { lru.removeAll(where: {$0 == city}) lru.append(city) answer += 1 } else { if(lru.count == cacheSize){ lru.removeFirst() } lru.append(city) answer += 5 } } return answer }