We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 464fe0a commit f455833Copy full SHA for f455833
Solution/Day-097.cpp
@@ -0,0 +1,33 @@
1
+class TimeMap {
2
+public:
3
+ /** Initialize your data structure here. */
4
+ unordered_map<int , vector<pair<string , int>>>mp;
5
+ TimeMap() {
6
+
7
+ }
8
9
+ void set(string key, string value, int timestamp) {
10
+ mp[key].push_back(make_pair(value , timestamp));
11
12
13
+ string get(string key, int timestamp) {
14
+ const auto &v = mp[key];
15
+ if(v.size()==0){
16
+ return "";
17
18
+ auto c = upper_bound(v.begin() , v.end() ,
19
+ [](int val , auto &p){
20
+ return val < p.second;
21
22
+ );
23
+ return c.second;
24
25
+};
26
27
+/**
28
+ * Your TimeMap object will be instantiated and called as such:
29
+ * TimeMap* obj = new TimeMap();
30
+ * obj->set(key,value,timestamp);
31
+ * string param_2 = obj->get(key,timestamp);
32
+ */
33
0 commit comments