Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TimeMap {
- public:
- unordered_map<string, map<int, string>> m;
- /** Initialize your data structure here. */
- TimeMap() {
- }
- void set(string key, string value, int timestamp) {
- m[key].insert({timestamp, value});
- }
- string get(string key, int timestamp) {
- auto it = m[key].upper_bound(timestamp);
- if(it == m[key].begin())
- return "";
- 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);
- */
Advertisement
Add Comment
Please, Sign In to add comment