手写LRU
笔试、面试的常客 - 手写LRU,一般是使用双链表和哈希表来做实现:
class LRUCache {
int capacity;
int size;
Map<Integer, Node> map = new HashMap<>();
Node head;
Node tail;
public LRUCache(int capacity) {
this.capacity = capacity;
size = 0;
head = new Node();
tail = new Node();
head.next = tail;
tail.pre = head