1차 캐시
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
- 내 풀이
- cacheSize==0 일 때 고려해야 함
from collections import deque
def solution(cacheSize, cities):
queue=deque()
answer=0
if cacheSize==0:
return len(cities)*5
for city in cities:
city=city.upper()
if city in queue:
answer+=1 #캐시히트
queue.remove(city)
queue.append(city)
else:
if len(queue)>=cacheSize and queue:
queue.popleft()
answer+=5 #캐시미스
queue.append(city)
return answer
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
| [프로그래머스] [Level 2] [2018 KAKAO BLIND RECRUITMENT 1차] 뉴스 클러스터링 (0) | 2022.09.27 |
|---|---|
| [프로그래머스] [Level 2] n^2 배열 자르기 (0) | 2022.09.22 |
| [프로그래머스] [Level 2] 이진 변환 반복하기 (0) | 2022.09.12 |
| [프로그래머스] [Level 2] [DFS/BFS] 게임 맵 최단거리 (0) | 2022.09.10 |
| [프로그래머스] [Level 2] [DFS/BFS] 타겟 넘버 (0) | 2022.09.05 |