跳转至

日志速率限制器⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

class Logger {
private:
    unordered_map<string, int> msgToTime;
public:
    Logger() {

    }

    bool shouldPrintMessage(int timestamp, string message) {
        if (!msgToTime.count(message)) {
            msgToTime[message] = timestamp;
            return true;
        } 

        if (timestamp - msgToTime[message] >= 10) {
            msgToTime[message] = timestamp;
            return true;
        } else {
            return false;
        }
    }
};

/**
 * Your Logger object will be instantiated and called as such:
 * Logger* obj = new Logger();
 * bool param_1 = obj->shouldPrintMessage(timestamp,message);
 */