Created
September 14, 2018 15:17
-
-
Save junho85/0d8c4beb0441bb0337914ca6e69dd915 to your computer and use it in GitHub Desktop.
ps3-cache.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def solution(cacheSize, cities): | |
answer = 0 | |
q = deque(maxlen=cacheSize) | |
for item in cities: | |
item = item.lower() | |
if item in q: | |
answer += 1 | |
q.remove(item) | |
q.append(item) | |
else: | |
answer += 5 | |
q.append(item) | |
return answer | |
assert(solution(3, ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA"]) == 50) | |
assert(solution(3, ["Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul"]) == 21) | |
assert(solution(2, ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "SanFrancisco", "Seoul", "Rome", "Paris", "Jeju", "NewYork", "Rome"]) == 60) | |
assert(solution(5, ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "SanFrancisco", "Seoul", "Rome", "Paris", "Jeju", "NewYork", "Rome"]) == 52) | |
assert(solution(2, ["Jeju", "Pangyo", "NewYork", "newyork"]) == 16) | |
assert(solution(0, ["Jeju", "Pangyo", "Seoul", "NewYork", "LA"]) == 25) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
블로그: http://junho85.pe.kr/1082