코딩 테스트/문제 풀기
[프로그래머스] 캐시
hazel_
2021. 3. 29. 13:02
programmers.co.kr/learn/courses/30/lessons/17680
from collections import deque
def solution(cacheSize, cities):
if cacheSize==0:
return len(cities)*5
q=deque()
time=0
for city in cities:
city=city.lower()
if city in q:
q.remove(city)
q.append(city)
time+=1
else:
if len(q) == cacheSize:
q.popleft()
q.append(city)
time+=5
return time