We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class TimeMap { public: unordered_map<string, set<pair<int,string>>> mp; TimeMap() { mp.clear(); }
void set(string key, string value, int timestamp) { mp[key].insert({timestamp, value}); } string get(string key, int timestamp) { if(mp[key].size() != 0){ auto it = mp[key].upper_bound({timestamp, "~"}); if(it == mp[key].begin()) return ""; --it; return it->second; } return ""; }
};
The text was updated successfully, but these errors were encountered:
Try this
#include <unordered_map> #include <map> #include <string> class TimeMap { public: std::unordered_map<std::string, std::map<int, std::string>> mp; TimeMap() { mp.clear(); } void set(const std::string& key, const std::string& value, int timestamp) { mp[key][timestamp] = value; } std::string get(const std::string& key, int timestamp) { auto& time_map = mp[key]; auto it = time_map.upper_bound(timestamp); if (it == time_map.begin()) { return ""; } --it; return it->second; } };
Sorry, something went wrong.
No branches or pull requests
class TimeMap {
public:
unordered_map<string, set<pair<int,string>>> mp;
TimeMap() {
mp.clear();
}
};
The text was updated successfully, but these errors were encountered: