Untitled
Anonymous
plain_text
02/11/2026 10:10 PM
692 B
19
Indexable
class LRUCache extends LinkedHashMap<Integer, Integer> {
private int capacity;
public LRUCache(int capacity) {
super(capacity, 1, true);
this.capacity = capacity;
}
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > capacity;
}
public int get(int key) {
return format(super.get(key));
}
private int format(Integer value) {
if (value == null) {
return -1;
}
return value;
}
}Editor is loading...
Leave a Comment