Object-Oriented Programming · ByteDance · Medium
Design and implement an LRUCache class (a cache that, when full, discards the least recently used entry). Both get(key) and put(key, value) must run in average $$O(1)$$ time. get returns the value stored under key, or -1 when the key is absent. A successful get also marks that key as the most recently used entry. put writes value under key. If the key already exists, its value is replaced and it becomes the most recently used entry. If the key is new, the pair is added, and…