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

Method get

python3/Linked Lists/lru_cache.py:20–27  ·  view source on GitHub ↗
(self, key: int)

Source from the content-addressed store, hash-verified

18 self.tail.prev = self.head
19
20 def get(self, key: int) -> int:
21 if key not in self.hashmap:
22 return -1
23 # To make this key the most recently used, remove its node and
24 # re-add it to the tail of the linked list.
25 self.remove_node(self.hashmap[key])
26 self.add_to_tail(self.hashmap[key])
27 return self.hashmap[key].val
28
29 def put(self, key: int, value: int) -> None:
30 # If a node with this key already exists, remove it from the

Calls 2

remove_nodeMethod · 0.95
add_to_tailMethod · 0.95

Tested by

no test coverage detected