2026年游戏行业程序员面试题目解析.docxVIP

  • 0
  • 0
  • 约9.48千字
  • 约 26页
  • 2026-11-09 发布于福建
  • 举报

第PAGE页共NUMPAGES页

2026年游戏行业程序员面试题目解析

一、编程语言与数据结构(10题,每题10分,共100分)

1.题目:

请用C++实现一个LRU(最近最少使用)缓存,支持get和put操作。缓存容量为固定值,超出容量时需要删除最久未使用的元素。要求时间复杂度为O(1)。

答案:

cpp

includeunordered_map

includelist

classLRUCache{

public:

LRUCache(intcapacity):capacity_(capacity){}

intget(intkey){

autoit=cache_map.find(key);

if(it==cache_map.end())return-1;

//Moveaccessednodetofront

cache_list.splice(cache_list.begin(),cache_list,it-second);

returnit-second-second;

}

voidput(intkey,intvalue){

autoit=cache_map.find(key);

if(it!=cache_map.end()){

//Updatevalueandmovetofr

文档评论(0)

1亿VIP精品文档

相关文档