We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
structLRUCache:Cache{std::vector<std::pair<int,int>>list{};LRUCache(intn){this->cp=n;}voidset(inta,intb)override{constautoiter=std::find_if(list.begin(),list.end(),[a](constauto&c){returna==c.first;});if(iter!=list.end()){// same key foundlist.erase(iter);}else{if(this->cp==list.size()){// max sizelist.erase(list.begin());}}list.push_back({a,b});}intget(inta)override{constautoiter=std::find_if(list.begin(),list.end(),[a](constauto&c){returna==c.first;});if(iter!=list.end()){returniter->second;}return-1;}};
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Abstract Classes - Polymorphism
You are viewing a single comment's thread. Return to all comments →
alll passed ! Could I get any feedback on this ?