@@ -0,0 +1,1748 @@
+/**%0A * %0A */%0Apackage leetcode;%0A%0Aimport java.util.HashMap;%0A%0A/**%0A * Problem: https://leetcode.com/problems/lru-cache%0A * %0A * @author Sudharsanan Muralidharan%0A */%0Apublic class LRUCache %7B%0A  class Node %7B%0A    int key, value;%0A    Node next = null;%0A    Node prev = null;%0A%0A    public Node(int key, int value) %7B%0A      this.key = key;%0A      this.value = value;%0A    %7D%0A  %7D%0A%0A  private HashMap%3CInteger, Node%3E map = null;%0A  private Node head = null;%0A  private Node tail = null;%0A  private int capacity = 0;%0A%0A  public LRUCache(int capacity) %7B%0A    this.capacity = capacity;%0A    map = new HashMap%3CInteger, Node%3E();%0A  %7D%0A%0A  public int get(int key) %7B%0A    Node node = map.get(key);%0A    if (node == null) %7B%0A      return -1;%0A    %7D%0A    shiftToTail(node);%0A    return node.value;%0A  %7D%0A  %0A  private void shiftToTail(Node node) %7B%0A    if(!node.equals(tail)) %7B%0A      if(node.equals(head)) %7B%0A        head.next.prev = null;%0A        head = head.next;%0A      %7D else %7B%0A        node.next.prev = node.prev;%0A        node.prev.next = node.next;%0A      %7D%0A      %0A      addToTail(node);%0A    %7D%0A  %7D%0A  %0A  private void addToTail(Node node) %7B%0A      tail.next = node;%0A      node.prev = tail;%0A      node.next = null;%0A      tail = node;%0A  %7D%0A  %0A  public void put(int key, int value) %7B%0A    if(map.containsKey(key)) %7B%0A        Node node = map.get(key);%0A        node.value = value;%0A        shiftToTail(node);%0A    %7D else %7B%0A        Node node = new Node(key, value);%0A        map.put(key, node);%0A        if(tail == null) %7B%0A          head = tail = node;%0A        %7D else %7B%0A          addToTail(node);%0A        %7D%0A        %0A        if(map.size() %3E capacity) %7B%0A          map.remove(head.key);%0A          if(head.next != null) %7B%0A            head.next.prev = null;%0A          %7D%0A          head = head.next;%0A        %7D%0A    %7D%0A  %7D%0A%7D%0A

Add solution for LRUCache Leetcode problem