내 풀이
from collections import deque
def solution(cacheSize, cities):
# 변수 초기화
answer = 0
cache = deque(maxlen=cacheSize) # deque 최대 크기 설정
# 대소문자 구분 없으므로 전체 lower case 변환
def lower(x):
return x.lower()
cities = list(map(lower, cities))
for city in cities:
# cache에 있을 경우
if city in cache:
answer += 1
cache.remove(city)
cache.append(city)
# cache에 없을 경우
elif city not in cache:
answer += 5
cache.append(city)
return answer
메모
알고리즘 공부해야겠다. LRU 설명은 아래 참고함.
'PROGRAMMERS' 카테고리의 다른 글
[프로그래머스/파이썬] 롤케이크 자르기 (0) | 2025.01.15 |
---|---|
[프로그래머스/파이썬] 튜플 (0) | 2025.01.14 |
[프로그래머스/파이썬] [PCCP 기출문제] 1번 / 동영상 재생기 (0) | 2025.01.10 |
[프로그래머스/파이썬] [PCCE 기출문제] 10번 / 공원 (13) | 2025.01.09 |
[프로그래머스/파이썬] [PCCE 기출문제] 9번 / 지폐 접기 (2) | 2025.01.07 |