Logger Rate Limiter

做一个简单的rate limiter, 要求10秒内不能有重复的message. 直接用map做.

class Logger {
    Map<String, Integer> m;
    /** Initialize your data structure here. */
    public Logger() {
       m = new HashMap<>(); 
    }
    
    /** Returns true if the message should be printed in the given timestamp, otherwise returns false.
        If this method returns false, the message will not be printed.
        The timestamp is in seconds granularity. */
    public boolean shouldPrintMessage(int timestamp, String message) {
        if(!m.containsKey(message)) {
            m.put(message, timestamp);
            return true;
        } else {
            if(timestamp - m.get(message) >= 10) {   
                m.put(message, timestamp);
                return true;
            }
            else {
                return false;
            }
        }
    }
}

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