2026年工程师面试题及答案含项目经验.docxVIP

  • 0
  • 0
  • 约5.07千字
  • 约 14页
  • 2026-03-05 发布于福建
  • 举报

2026年工程师面试题及答案含项目经验.docx

第PAGE页共NUMPAGES页

2026年工程师面试题及答案含项目经验

一、编程基础与算法(20分,共4题)

1.基本数据结构实现(5分)

题目:请用Python实现一个简单的LRU(最近最少使用)缓存,要求提供get和put方法,并解释实现原理。

答案:

python

classLRUCache:

def__init__(self,capacity:int):

self.capacity=capacity

self.cache={}

self.order=[]

defget(self,key:str)-int:

ifkeyinself.cache:

self.order.remove(key)

self.order.append(key)

returnself.cache[key]

return-1

defput(self,key:str,value:int):

ifkeyinself.cache:

self.order.remove(key)

eliflen(self.cache)=self.capacity:

oldest_key=self.order.pop(0)

delself.cache[oldest_key]

self.cache[key]=value

self.order.ap

文档评论(0)

1亿VIP精品文档

相关文档