C++_using map_122ms_83.65%_Accpeted!


  • 0
    class Logger {
    unordered_map<string, int> mp;
    public:
    /** Initialize your data structure here. */
    Logger() {
        //mp.clear();
    }
    
    bool shouldPrintMessage(int timestamp, string message) {
        if(mp.find(message) == mp.end()){
            mp.insert(pair<string, int>(message, timestamp));
            return true;
        }else{
            if(timestamp - mp[message] < 10){
                return false;
            }else{
                mp[message] = timestamp;
                return true;
            }
        }
    }
    };
    

    0_1476291278135_1CC5144D-6568-4088-862F-C4CDEE8B8825.png


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.