def solution(cacheSize, cities):
# ์บ์๊ฐ ์๋ค๋ฉด ์ ์ฒด ๋์ ๊ฐฏ์์ 5๋ฅผ ๊ณฑํ ์๊ฐ์ด ๊ฑธ๋ฆฐ๋ค
if cacheSize == 0:
return len(cities)*5
answer = 0
# ์บ์ ์ฌ์ด์ฆ์ ๋ง๋ ์บ์๋ฅผ ๋ง๋ ๋ค
cache = ["" for _ in range(cacheSize)]
for city in cities:
# ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ณํ์ง ์์ผ๋ฏ๋ก ์ ์ฒด ์๋ฌธ์๋ก ๋ฐ๊ฟ ์์
ํ๋ค
city = city.lower()
# ์บ์์ ์๋ค๋ฉด 1์ด๋ฅผ ๋ํ๊ณ ํด๋น ์๋ฃ๋ฅผ ์ญ์ ํ๋ค
if city in cache:
answer += 1
cache.remove(city)
# ์บ์์ ์๋ค๋ฉด 5์ด๋ฅผ ๋ํ๊ณ ๊ฐ์ฅ ์ค๋๋ ์๋ฃ๋ฅผ ์ญ์ ํ๋ค
else:
answer += 5
cache.pop(0)
# ์ง๊ธ ๋์จ ๋จ์ด๋ฅผ ๊ฐ์ฅ ์ต์ ์๋ฃ๋ผ๊ณ ์
๋ฐ์ดํธ ํ๋ค
cache.append(city)
return answer