2026年阿里巴巴技术岗面试题集及答案.docxVIP

  • 0
  • 0
  • 约4.3千字
  • 约 13页
  • 2026-08-31 发布于福建
  • 举报

2026年阿里巴巴技术岗面试题集及答案.docx

第PAGE页共NUMPAGES页

2026年阿里巴巴技术岗面试题集及答案

一、编程题(共5题,每题20分,总分100分)

1.题目(20分):

实现一个LRU(LeastRecentlyUsed)缓存机制,支持get和put操作。缓存容量为固定值,当缓存满时,最久未使用的元素将被移除。请用Java或Python实现,并说明时间复杂度。

答案:

Java实现:

java

importjava.util.HashMap;

importjava.util.Map;

classLRUCacheK,V{

privatefinalintcapacity;

privatefinalMapK,Nodemap;

privateNodehead,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

文档评论(0)

1亿VIP精品文档

相关文档