Skip to content
New issue

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

Leetcode 981. Time Based Key-Value Store #699

Open
NarpatAanjana opened this issue Oct 6, 2022 · 0 comments
Open

Leetcode 981. Time Based Key-Value Store #699

NarpatAanjana opened this issue Oct 6, 2022 · 0 comments

Comments

@NarpatAanjana
Copy link
Contributor

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 "";
}

};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant