キャッシュ(Programmers 17680)
🧑💻 キャッシュ
cacheSizecitiesreturn3["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA"]503["Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul"]212["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "SanFrancisco", "Seoul", "Rome", "Paris", "Jeju", "NewYork", "Rome"]605["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "SanFrancisco", "Seoul", "Rome", "Paris", "Jeju", "NewYork", "Rome"]522["Jeju", "Pangyo", "NewYork", "newyork"]160["Jeju", "Pangyo", "Seoul", "NewYork", "LA"]25
📌 LRUアルゴリズムを使う!
📌 Cache hit:すでに存在する場合、cache miss:存在しない場合
🧑💻 解決策
🧑💻 コード#コード#
def solution(cacheSize, cities) :
answer = 0
cache = []
if cacheSize == 0 :
return len(cities) * 5
for city in cities :
city = city.lower()
if not city in cache :
if len(cache) < cacheSize :
answer += 5
cache.append(city)
else :
answer += 5
cache.pop(0)
cache.append(city)
else :
answer += 1
cache.remove(city)
cache.append(city)
return answer
🧑💻 総評
これは簡単な問題です.
Reference
この問題について(キャッシュ(Programmers 17680)), 我々は、より多くの情報をここで見つけました https://velog.io/@moonpiderman/캐시-Programmers-17680テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol