Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. set(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
Analysis
Implement an LRU cache. I won't go into the definition of a least recently used (LRU) list. The get method needs to look up a value by its key, so of course I need a map, called an associative array in Python. LeetCode marks this problem as Hard, but it's really just an engineering problem.
Also, it looks like the test cases for this problem don't cover capacity=0? Is this the LeetCode I know?