class LRUCache:
def __init__(self, capacity):
self.capacity = capacity
self.cache = {}
def get(self, key):
if key not in self.cache:
return -1
value = self.cache.pop(key)
self.cache[key] = value
return value
def put(self, key, value):
if self.capacity <= 0:
return
if key in self.cache:
self.cache.pop(key)
elif len(self.cache) >= self.capacity:
oldest = next(iter(self.cache))
del self.cache[oldest]
self.cache[key] = value