← 返回 citadel 的题目列表LRU Cache Implementation
类型:online_judge
citadel
Implement a LRU (Least Recently Used) cache system with get and put methods. get(key) - Retrieve the value if the key exists in the cache, otherwise return -1. Accessing a key marks it as recently used. put(key, value) - Insert a key-value pair, if the cache is full, remove the least recently used entry to make room for the new one. Complete these operations in O(1) time complexity. Assume the maximum capacity of the cache does not exceed 1000.
Example
Input
3
put 1 1
put 2 2
get 1