-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLRUAlgorithm.py
More file actions
46 lines (28 loc) · 1.16 KB
/
LRUAlgorithm.py
File metadata and controls
46 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from collections import deque
if __name__ == '__main__':
def solution(cities, cacheSize):
answer = 0
cache = []
for city in cities:
city = city.lower()
if city in cache:
answer += 1
# 이건 뭐?
# if len(cache) >= cacheSize:
# 갱신
cache.remove(city)
cache.append(city)
#?
# else:
# cache.append(city)
else:
answer += 5
if cacheSize != 0:
# cacheSize 보다 길수는 없다. 있으면 갱신하고 없으면 채우도록 짠다면
if len(cache) == cacheSize:
# 삭제
cache.pop(0)
cache.append(city)
return answer
assert solution(["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA"],3) , solution(["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA"],3)
# solution 1 (가장 쓰이지 않은 요소가 리스트의 첫 번째 요소 )