|
| 1 | +from collections import deque |
| 2 | + |
| 3 | + |
| 4 | +def solution(cacheSize, cities): |
| 5 | + result = 0 |
| 6 | + if cacheSize == 0: return len(cities) * 5 |
| 7 | + q = deque(maxlen=cacheSize) |
| 8 | + |
| 9 | + cities = [c.lower() for c in cities] |
| 10 | + |
| 11 | + for city in cities: |
| 12 | + if city not in q: |
| 13 | + q.append(city) |
| 14 | + result += 5 |
| 15 | + else: |
| 16 | + q.remove(city) |
| 17 | + q.append(city) |
| 18 | + result += 1 |
| 19 | + |
| 20 | + return result |
| 21 | + |
| 22 | + |
| 23 | +print(solution(3, ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA"])) |
| 24 | +print(solution(3, ["Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul"])) |
| 25 | +print(solution(2, ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "SanFrancisco", "Seoul", "Rome", "Paris", "Jeju", "NewYork", "Rome"] )) |
| 26 | +print(solution(5, ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "SanFrancisco", "Seoul", "Rome", "Paris", "Jeju", "NewYork", "Rome"] )) |
| 27 | +print(solution(2, ["Jeju", "Pangyo", "NewYork", "newyork"] )) |
| 28 | +print(solution(0, ["Jeju", "Pangyo", "Seoul", "NewYork", "LA"] )) |
0 commit comments