Implement the Least Recently Used (LRU) cache class:
- LRUCache(int capacity) Initialize the LRU cache with positive size capacity.
- get(key) Return the value of the key if the key exists, otherwise return -1.
- void put(key, value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache.
- If the number of keys exceeds the capacity from this operation, evict old key.
- Follow up: Could you do get and put in O(1) time complexity?
Example 1: