Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LRUCache {
- class LRUMap<K, V> extends LinkedHashMap<K, V>{
- int size;
- public LRUMap(int size) {
- super(size, 0.75f, true);
- this.size = size;
- }
- @Override
- protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
- return size() > size;
- }
- }
- LRUMap<Integer, Integer> map;
- public LRUCache(int capacity) {
- map = new LRUMap<>(capacity);
- }
- public int get(int key) {
- return map.getOrDefault(key, -1);
- }
- public void put(int key, int value) {
- map.put(key, value);
- }
- }
Add Comment
Please, Sign In to add comment