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

Method get

cpp/Linked Lists/lru_cache.cpp:43–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41 }
42
43 int get(int key) {
44 if (hashmap.find(key) == hashmap.end()) {
45 return -1;
46 }
47 // To make this key the most recently used, remove its node and
48 // re-add it to the tail of the linked list.
49 removeNode(hashmap[key]);
50 addToTail(hashmap[key]);
51 return hashmap[key]->val;
52 }
53
54 void put(int key, int val) {
55 // If a node with this key already exists, remove it from the

Calls 1

findMethod · 0.45

Tested by

no test coverage detected