public class LRUCache {
  private class Node {
    Node prev;
    Node next;
    int key;
    int value;
    
    public Node(int key, int value) {
      this.key = key;
      this.value = value;
      this.prev = null;
      this.next = null;
    }
  }
  
  private int capacity;
  private HashMap<Integer, Node> map = new HashMap<Integer, Node>();
  private Node head = new Node(-1, -1);
  private Node tail = new Node(-1, -1);
  
  public LRUCache(int capacity) {
    this.capacity = capacity;
    tail.prev = head;
    head.next = tail;
  }
  
  public int get(int key) {
    if (!map.containsKey(key)) {
      return -1;
    }
    // remove current
    Node cur = map.get(key);
    cur.prev.next = cur.next;
    cur.next.prev = cur.prev;
    
    // move current to tail
    move_to_tail(cur);
    
    return map.get(key).value;
  }
  
  private void move_to_tail(Node cur) {
    cur.prev = tail.prev;
    tail.prev = cur;
    cur.prev.next = cur;
    cur.next = tail;
    
  }
}

@@ -977,10 +977,369 @@
    %0A  %7D%0A
+  %0A  public void set(int key, int value) %7B%0A    if (map.get(key) != -1) %7B%0A      map.get(key).value = value;%0A      return;%0A    %7D%0A    if (map.size() == capacity) %7B%0A      map.remove(head.next.key);%0A      head.next = head.next.next;%0A      head.next.prev = head;%0A    %7D%0A    Node insert = new Node(key, value);%0A    map.put(key, insert);%0A    move_to_tail(insert);%0A  %7D%0A
 %7D%0A

Update LRUCache.java