Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
31 lines (25 loc) · 708 Bytes

File metadata and controls

31 lines (25 loc) · 708 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package leetcode._146_;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Created by zhangbo54 on 2019-07-23.
*/
class LRUCache2<K, V> extends LinkedHashMap<K, V> {
private int maxSize;
public LRUCache2(int maxSize) {
// 第三个参数表示是否按照访问顺序组织链表
super(maxSize, 0.75f, true);
this.maxSize = maxSize;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return this.size() > maxSize;
}
}
/**
* Your LRUCache object will be instantiated and called as such:
* LRUCache obj = new LRUCache(capacity);
* int param_1 = obj.get(key);
* obj.put(key,value);
*/
Morty Proxy This is a proxified and sanitized view of the page, visit original site.