We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 57dbe88 commit 5ff6b83Copy full SHA for 5ff6b83
lru_cache.cpp
@@ -13,15 +13,15 @@ class LRUCache {
13
mp[key].second = keys.begin(); //update map
14
return mp[key].first;
15
}
16
- else return -1;
+ return -1;
17
18
19
void put(int key, int value) {
20
if(mp.find(key) != mp.end()) { //key already exists in the map
21
//same operations as that of get operation
22
keys.erase(mp[key].second);
23
keys.push_front(key);
24
- mp[key].second = keys.begin();
+ mp[key] = {value, keys.begin()};
25
26
else {
27
if(keys.size() == capacity) {
0 commit comments