1 parent a1862bb commit 8633ea6Copy full SHA for 8633ea6
1 file changed
LRUCache.java
@@ -1,5 +1,5 @@
1
/*
2
- Author: King, nkuwjg@gmail.com
+ Author: Andy, nkuwjg@gmail.com
3
Date: March 12, 2014
4
Problem: LRU Cache
5
Difficulty: Hard
@@ -20,7 +20,7 @@ public class LRUCache {
20
private int capacity;
21
public LRUCache(int capacity) {
22
this.capacity = capacity;
23
- map = new LinkedHashMap<Integer, Integer>(capacity);
+ map = new LinkedHashMap<Integer, Integer>(capacity + 1);
24
}
25
26
public int get(int key) {
@@ -37,4 +37,4 @@ public void set(int key, int value) {
37
if (map.size() > capacity)
38
map.remove(map.entrySet().iterator().next().getKey());
39
40
-}
+}
0 commit comments