LeetCode solver
Snap a LeetCode, HackerRank or CoderPad problem and get working Python, C++, Java or Go with time and space complexity.
class LRUCache:
def __init__(self, capacity):
self.cap, self.cache = capacity, OrderedDict()
def get(self, key):
if key not in self.cache: return -1
self.cache.move_to_end(key)
return self.cache[key] # O(1)