Skip to content

Commit f67f405

Browse files
Sync LeetCode submission Runtime - 76 ms (15.94%), Memory - 140 MB (5.35%)
1 parent afb2fae commit f67f405

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

LeetCode/1023-time-based-key-value-store/solution.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
class TimeMap {
2-
public:
32
unordered_map<string, set<pair<int, string>>> mp;
3+
public:
44
void set(string key, string value, int timestamp) {
55
mp[key].insert({timestamp, value});
66
}
77

88
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;
9+
auto it = mp[key].upper_bound({timestamp, string(1, char(255))});
10+
if (it == mp[key].begin()) return "";
11+
return (--it)->second;
1412
}
1513
};
1614

0 commit comments

Comments
 (0)