-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path981.cpp
More file actions
26 lines (22 loc) · 711 Bytes
/
981.cpp
File metadata and controls
26 lines (22 loc) · 711 Bytes
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
class TimeMap {
public:
unordered_map<string, map<int, string>> key2values; // {key, {timestamp, value}}
TimeMap() {
}
void set(string key, string value, int timestamp) {
key2values[key][timestamp] = value;
}
string get(string key, int timestamp) {
if (key2values.find(key) == key2values.end()) return "";
auto it = key2values[key].upper_bound(timestamp);
if (it == key2values[key].begin()) return "";
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);
*/