-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDay-097.cpp
33 lines (28 loc) · 815 Bytes
/
Day-097.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class TimeMap {
public:
/** Initialize your data structure here. */
unordered_map<int , vector<pair<string , int>>>mp;
TimeMap() {
}
void set(string key, string value, int timestamp) {
mp[key].push_back(make_pair(value , timestamp));
}
string get(string key, int timestamp) {
const auto &v = mp[key];
if(v.size()==0){
return "";
}
auto c = upper_bound(v.begin() , v.end() ,
[](int val , auto &p){
return val < p.second;
}
);
return c.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);
*/