Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get
and put
.
Also, creating a new cache object should take an integer for the capacity of the cache. It should either be required or default to a value.
get(key)
- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.