-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[1차] 캐시.py
32 lines (31 loc) · 898 Bytes
/
[1차] 캐시.py
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
from collections import deque
def solution(cacheSize, cities):
queue = deque()
cache = 0
times = 0
if cacheSize == 0:
return len(cities)*5
for el in cities:
if cache < cacheSize:
if len(queue)==0:
times += 5
queue.append(el.lower())
cache += 1
elif el.lower() in queue:
times += 1
queue.remove(el.lower())
queue.append(el.lower())
else:
queue.append(el.lower())
times += 5
cache += 1
else:
if el.lower() in queue:
times += 1
queue.remove(el.lower())
queue.append(el.lower())
else:
queue.popleft()
queue.append(el.lower())
times += 5
return times