2026年饿了么技术部门面试技巧及答案详解.docxVIP

  • 0
  • 0
  • 约7.27千字
  • 约 21页
  • 2026-11-17 发布于福建
  • 举报

2026年饿了么技术部门面试技巧及答案详解.docx

第PAGE页共NUMPAGES页

2026年饿了么技术部门面试技巧及答案详解

一、编程能力测试(共5题,每题20分,总分100分)

1.题目:实现一个简单的LRU(LeastRecentlyUsed)缓存机制,支持get和put操作。请用Python或Java实现,并说明时间复杂度和空间复杂度。

答案:

python

classLRUCache:

def__init__(self,capacity:int):

self.capacity=capacity

self.cache={}

self.order=[]

defget(self,key:int)-int:

ifkeyinself.cache:

self.order.remove(key)

self.order.append(key)

returnself.cache[key]

else:

return-1

defput(self,key:int,value:int)-None:

ifkeyinself.cache:

self.order.remove(key)

eliflen(self.cache)=self.capacity:

oldest_key=self.order.pop(0)

delself.cache[oldest_key

文档评论(0)

1亿VIP精品文档

相关文档