Haribo ML, AI, MATH, Algorithm

[1차] 캐시


[1차] 캐시

def solution(cacheSize, cities):
    if cacheSize == 0 : return 5*len(cities)
    cities = [x.lower() for x in cities]
    LRU = []
    cost = 0
    for city in cities :
        if city in LRU :
            LRU.pop(LRU.index(city))
            cost += 1
        else :
            if len(LRU) >= cacheSize:
                LRU.pop(0)
            cost += 5
        LRU.append(city)
    return cost

Similar Posts

다음 포스트 [1차] 프렌즈4블록

Comments