Title of your comment slo simple map and list


#1

Comment body goes here.

include<bits/stdc++.h>

using namespace std;
unordered_map<int,int> m;
int c;
list l;
LRUCache::LRUCache(int capacity) {
m.clear();
l.clear();
c=capacity;
}

int LRUCache::get(int key) {
if(m.find(key)==m.end() || m.size()==0) return -1;
l.remove(key);
l.push_front(key);
return m[key];
}

void LRUCache::set(int key, int value) {
if(m.find(key)==m.end()){
if(l.size()==c){
auto k=l.back();
l.remove(k);
m.erase(k);
}
}
else l.remove(key);
m[key]=value;
l.push_front(key);

}