mirror of
https://github.com/prdlk/leetcode.git
synced 2026-09-16 23:16:26 +00:00
docs(docs): clarify LRUCache insertion order in example MDX
This commit is contained in:
@@ -47,10 +47,11 @@ class LRUCache:
|
||||
next_node.prev = prev_node
|
||||
|
||||
def _add_node(self, node):
|
||||
node.prev = self.head
|
||||
node.next = self.head.next
|
||||
self.head.next.prev = node # pyright: ignore[reportAttributeAccessIssue]
|
||||
self.head.next = node
|
||||
# Insert just before the tail (most recent at end)
|
||||
node.next = self.tail
|
||||
node.prev = self.tail.prev
|
||||
self.tail.prev.next = node # pyright: ignore[reportAttributeAccessIssue]
|
||||
self.tail.prev = node
|
||||
|
||||
def get(self, key: int) -> int:
|
||||
if key not in self.cache:
|
||||
@@ -73,7 +74,7 @@ class LRUCache:
|
||||
self._add_node(new_node)
|
||||
|
||||
if len(self.cache) > self.capacity:
|
||||
lru = self.tail.prev
|
||||
lru = self.head.next # Oldest node is next to the head
|
||||
self._remove_node(lru)
|
||||
del self.cache[lru.key] # pyright: ignore[reportAttributeAccessIssue]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user