2026年软件工程师技术面试练习题及解析.docxVIP

  • 1
  • 0
  • 约8.34千字
  • 约 24页
  • 2026-09-25 发布于福建
  • 举报

2026年软件工程师技术面试练习题及解析.docx

第PAGE页共NUMPAGES页

2026年软件工程师技术面试练习题及解析

一、编程实现题(共5题,每题10分,总分50分)

题目1(Java):

实现一个LRU(LeastRecentlyUsed)缓存,支持容量设定。当缓存容量满时,需要淘汰最久未使用的元素。提供`get`和`put`方法,分别用于获取和添加元素。要求时间复杂度为O(1)。

答案:

java

importjava.util.HashMap;

importjava.util.Map;

publicclassLRUCacheK,V{

privatefinalintcapacity;

privatefinalMapK,Nodecache;

privatefinalNodehead,tail;

privatestaticclassNodeK,V{

Kkey;

Vvalue;

NodeK,Vprev;

NodeK,Vnext;

Node(Kkey,Vvalue){

this.key=key;

this.value=value;

}

}

publicLRUCache(intcapacity){

this.capacity=capacity;

this.cache=newHashMap();

head=newNode

文档评论(0)

1亿VIP精品文档

相关文档