We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent afb2fae commit f67f405Copy full SHA for f67f405
1 file changed
LeetCode/1023-time-based-key-value-store/solution.cpp
@@ -1,16 +1,14 @@
1
class TimeMap {
2
-public:
3
unordered_map<string, set<pair<int, string>>> mp;
+public:
4
void set(string key, string value, int timestamp) {
5
mp[key].insert({timestamp, value});
6
}
7
8
string get(string key, int timestamp) {
9
- auto& st = mp[key];
10
- auto ptr = st.upper_bound({timestamp, string(1, char(255))});
11
- if (ptr == st.begin()) return "";
12
- ptr--;
13
- return ptr->second;
+ auto it = mp[key].upper_bound({timestamp, string(1, char(255))});
+ if (it == mp[key].begin()) return "";
+ return (--it)->second;
14
15
};
16
0 commit comments