Skip to content

Leetcode 981. Time Based Key-Value Store #699

Description

@NarpatAanjana

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

};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions