MCPcopy Create free account
hub / github.com/ByteByteGoHq/coding-interview-patterns / __init__

Method __init__

python3/Linked Lists/lru_cache.py:9–18  ·  view source on GitHub ↗
(self, capacity: int)

Source from the content-addressed store, hash-verified

7
8class LRUCache:
9 def __init__(self, capacity: int):
10 self.capacity = capacity
11 # A hash map that maps keys to nodes.
12 self.hashmap = {}
13 # Initialize the head and tail dummy nodes and connect them to
14 # each other to establish a basic two-node doubly linked list.
15 self.head = DoublyLinkedListNode(-1, -1)
16 self.tail = DoublyLinkedListNode(-1, -1)
17 self.head.next = self.tail
18 self.tail.prev = self.head
19
20 def get(self, key: int) -> int:
21 if key not in self.hashmap:

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected