- 1
- 0
- 约7.07千字
- 约 21页
- 2026-06-03 发布于福建
- 举报
第PAGE页共NUMPAGES页
2026年高级软件工程师面试必答题库
一、编程实现题(共3题,每题20分)
1.题目:
实现一个LRU(最近最少使用)缓存机制,要求使用链表和哈希表结合的方式存储键值对,支持`get`和`put`操作。请写出核心代码实现,并说明时间复杂度和空间复杂度。
答案:
java
classLRUCacheK,V{
privatefinalintcapacity;
privatefinalMapK,NodeK,Vmap;
privatefinalNodeK,Vhead,tail;
publicLRUCache(intcapacity){
this.capacity=capacity;
this.map=newHashMap();
head=newNode(null,null);
tail=newNode(null,null);
head.next=tail;
tail.prev=head;
}
publicVget(Kkey){
NodeK,Vnode=map.get(key);
if(node==null)returnnull;
moveToHead(node);
returnnode.value;
}
publicvoidput(Kk
原创力文档

文档评论(0)