Reading:AWS re:Invent 2018: Running Serverless at The Edge (CTD302)
Tech:DNS探秘
Share:clion远程调试指南
Alogrithm
题目—LRU Cache
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.
Follow up: Could you do both operations in O(1) time complexity?
/** * Your LRUCache object will be instantiated and called as such: * LRUCache* obj = new LRUCache(capacity); * int param_1 = obj->get(key); * obj->put(key,value); */
structLRUNode { LRUNode *pre = nullptr; LRUNode *next = nullptr; int key; int val; };