https://leetcode-cn.com/problems/time-based-key-value-store/
思路:模拟题……
class TimeMap {
public:
/** Initialize your data structure here. */
TimeMap() {
}
void set(string key, string value, int timestamp) {
mp[key][timestamp]=value;
}
string get(string key, int timestamp) {
if(mp.count(key))
{
auto it=mp[key].upper_bound(timestamp);
if(it!=mp[key].begin())
return (--it)->second;
}
return "";
}
private:
unordered_map<string,map<int,string>> mp;
};
/**
* 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);
*/