面向腾子的leetcode刷题临阵磨枪说是NO.146 LRU缓存https://leetcode.cn/problems/lru-cache/solutions/259678/lruhuan-cun-ji-zhi-by-leetcode-solution/题目提到键值对,想到构建hash表,涉及到出入顺序,想到栈、队列和链表,由于要实现顺序更新,使用双向链表hash表键自设,值为指向链表元素的引用 双向链表键与hash表键一致,值为实际存储值class DLinkedNode: def __init__(self, key=0, value=0): self.key = key self.value = value self.prev = None self.next = None class LRUCache: def __init__(self, capacity: int): self.cache = dict() # 使用伪头部和伪尾部节点
punkginger
本质酒鬼