알고리즘/프로그래머스
2018 카카오 블라인드 - 캐시
토마토오이
2021. 4. 14. 09:45
LRU(Least Recently Used) Cache 알고리즘
: 가장 오래된 페이지부터 삭제
데이터 베이스의 메모리 관리의 가장 중요한 원리
python
memory = []; total = 0
lowArr = list(map(lambda x : x.lower(),arr))
for i in lowArr :
if i in memory :
total += 1
memory.remove(i) #메모리에 데이터가 있으면 삭제
else :
total += 5
memory.append(i) #새로운 데이터 추가
if len(memory) >= size : #주어진 메모리크기보다 크면 옛날데이터 삭제
del(memory[0])
return total
cacheProcess(['Jeju', 'Pangyo', 'Seoul', 'NewYork', 'LA', 'Jeju', 'Pangyo','Seoul', 'NewYork', 'LA'],3)
//실행결과 : 50