- 0
- 0
- 约8.37千字
- 约 22页
- 2026-03-24 发布于福建
- 举报
第PAGE页共NUMPAGES页
2026年美团技术大牛面试经验与题目解答
一、编程能力测试(共5题,每题20分,总分100分)
1.(20分)实现一个LRU(LeastRecentlyUsed)缓存机制,要求支持get和put操作,时间复杂度为O(1)。缓存容量为固定值。
答案与解析:
java
classLRUCacheK,V{
privatefinalintcapacity;
privatefinalMapK,NodeK,Vmap;
privatefinalNodeK,Vhead,tail;
staticclassNodeK,V{
Kkey;
Vvalue;
NodeK,Vprev,next;
Node(Kkey,Vvalue){
this.key=key;
this.value=value;
}
}
publicLRUCache(intcapacity){
this.capacity=capacity;
map=newHashMap();
head=newNode(null,null);
tail=newNode(null,null);
head.next=tail;
tail.prev=head;
}
publicVget(Kkey){
原创力文档

文档评论(0)