programmers.co.kr/learn/courses/30/lessons/17680
코딩테스트 연습 - [1차] 캐시
3 ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA"] 50 3 ["Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul"] 21 2 ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "SanFrancisco", "Seoul", "Ro
programmers.co.kr
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
'코딩 테스트 > 문제 풀기' 카테고리의 다른 글
[프로그래머스] 프렌즈4블록 (0) | 2021.03.30 |
---|---|
[프로그래머스] 뉴스 클러스터링 (0) | 2021.03.30 |
[프로그래머스] 예상 대진표 (0) | 2021.03.29 |
[프로그래머스] 영어 끝말 잇기 (0) | 2021.03.29 |
[프로그래머스] 점프와 순간 이동 (0) | 2021.03.29 |
댓글