MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / put

Method put

python/0146-lru-cache.py:33–43  ·  view source on GitHub ↗
(self, key: int, value: int)

Source from the content-addressed store, hash-verified

31 return -1
32
33 def put(self, key: int, value: int) -> None:
34 if key in self.cache:
35 self.remove(self.cache[key])
36 self.cache[key] = Node(key, value)
37 self.insert(self.cache[key])
38
39 if len(self.cache) > self.cap:
40 # remove from the list and delete the LRU from hashmap
41 lru = self.left.next
42 self.remove(lru)
43 del self.cache[lru.key]

Callers

nothing calls this directly

Calls 3

removeMethod · 0.95
insertMethod · 0.95
NodeClass · 0.70

Tested by

no test coverage detected