@@ -0,0 +1,1558 @@
+import java.util.LinkedHashMap;%0Aimport java.util.Map;%0A%0A/**%0A * Design and implement a data structure for Least Recently Used (LRU) cache.%0A * It should support the following operations: get and set.%0A *%0A * get(key) - Get the value (will always be positive) of the key if the key%0A * exists in the cache, otherwise return -1.%0A * (get means use, so we need to update)%0A *%0A * set(key, value) - Set or insert the value if the key is not already present.%0A * When the cache reached its capacity, it should invalidate the least recently%0A * used item before inserting a new item.%0A *%0A * Tags: Data Structure%0A */%0Aclass LRUCacheLinkedHashMap extends LinkedHashMap %7B%0A%0A    private final int capacity;%0A%0A    public LRUCacheLinkedHashMap(int capacity, float loadFactor) %7B%0A        super(capacity, loadFactor, true);%0A        this.capacity = capacity;%0A    %7D%0A%0A    public static void main(String arg%5B%5D) %7B%0A        LRUCacheLinkedHashMap lruCache = new LRUCacheLinkedHashMap(4, 0.75f);%0A%0A        lruCache.put(1, %22Object1%22);%0A        lruCache.put(2, %22Object2%22);%0A        lruCache.put(3, %22Object3%22);%0A        lruCache.get(1);%0A        lruCache.put(4, %22Object4%22);%0A        System.out.println(lruCache);%0A        lruCache.put(5, %22Object5%22);%0A        lruCache.get(3);%0A        lruCache.put(6, %22Object6%22);%0A        System.out.println(lruCache);%0A        lruCache.get(4);%0A        lruCache.put(7, %22Object7%22);%0A        lruCache.put(8, %22Object8%22);%0A        System.out.println(lruCache);%0A    %7D%0A%0A    @Override%0A    protected boolean removeEldestEntry(Map.Entry eldest) %7B%0A        return size() %3E capacity;%0A    %7D%0A%7D%0A

add LRU cache