C++ 4 lines hash table


  • 0
    class Logger {
    public:
        unordered_map<string,int>m;
    
        bool shouldPrintMessage(int timestamp, string message) {
            if(!m.count(message)) {m[message]=timestamp;return true;}
            if(timestamp-m[message]>=10) {m[message]=timestamp;return true;}
            else return false;
        }
    };
    

Log in to reply
 

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