Skip to content

Commit 5ff6b83

Browse files
Update lru_cache.cpp
1 parent 57dbe88 commit 5ff6b83

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lru_cache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ class LRUCache {
1313
mp[key].second = keys.begin(); //update map
1414
return mp[key].first;
1515
}
16-
else return -1;
16+
return -1;
1717
}
1818

1919
void put(int key, int value) {
2020
if(mp.find(key) != mp.end()) { //key already exists in the map
2121
//same operations as that of get operation
2222
keys.erase(mp[key].second);
2323
keys.push_front(key);
24-
mp[key].second = keys.begin();
24+
mp[key] = {value, keys.begin()};
2525
}
2626
else {
2727
if(keys.size() == capacity) {

0 commit comments

Comments
 (0)