## 题目

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.

get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
put(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.

The cache is initialized with a positive capacity.

Could you do both operations in O(1) time complexity?

Example:

## 思路

python中有序的哈希表: OrderedDict(), 存储的顺序按照进入字典的顺序。

• pop(key) - 得到key所对应的value
• popitem() - 得到最后一个进表的value
• popitem(last=False) - 得到第一个进表的value