Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TimeMap {
- public:
- /** Initialize your data structure here. */
- std::unordered_map<std::string,std::map<int,string>> timeMap;
- TimeMap() {
- }
- void set(string key, string value, int timestamp) {
- timeMap[key][timestamp]=value;
- }
- string get(string key, int timestamp) {
- if (timeMap.find(key)==timeMap.end())
- return "";
- auto it = std::lower_bound(timeMap[key].begin(), timeMap[key].end(), timestamp, [](const auto& a, const auto& b)->bool{return a.first<b;});
- if (it==timeMap[key].begin())
- return "";
- if (it==timeMap[key].end())
- it--;
- return it->second;
- }
- };
- /**
- * Your TimeMap object will be instantiated and called as such:
- * TimeMap* obj = new TimeMap();
- * obj->set(key,value,timestamp);
- * string param_2 = obj->get(key,timestamp);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement