Logger Rate Limiter

Posted keepshuatishuati

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Logger Rate Limiter相关的知识,希望对你有一定的参考价值。

 1 public class Logger {
 2     private Map<String, Integer> data;
 3     /** Initialize your data structure here. */
 4     public Logger() {
 5         data = new HashMap<>();
 6     }
 7     
 8     /** Returns true if the message should be printed in the given timestamp, otherwise returns false.
 9         If this method returns false, the message will not be printed.
10         The timestamp is in seconds granularity. */
11     public boolean shouldPrintMessage(int timestamp, String message) {
12         if (!data.containsKey(message) || timestamp - data.get(message) >= 10) {
13             data.put(message, timestamp);
14             return true;
15         }
16         return false;
17     }
18 }
19 
20 /**
21  * Your Logger object will be instantiated and called as such:
22  * Logger obj = new Logger();
23  * boolean param_1 = obj.shouldPrintMessage(timestamp,message);
24  */

 

以上是关于Logger Rate Limiter的主要内容,如果未能解决你的问题,请参考以下文章

Logger Rate Limiter

Logger Rate Limiter

Leetcode: Logger Rate Limiter

Leetcode 359: Logger Rate Limiter

[LC] 359. Logger Rate Limiter

[LeetCode] Logger Rate Limiter 记录速率限制器