Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.
get(key) - Get the value (will always be positive) of
the key if the key exists in the cache, otherwise return -1.
set(key, value) - Set or insert the value if the key
is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.

本文详细阐述了Least Recently Used (LRU)缓存的数据结构设计及其实现方式,包括get和set操作的优化策略,以及当缓存容量达到上限时如何淘汰最不经常使用的项。
773

被折叠的 条评论
为什么被折叠?



