forked from jsjtzyy/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC359_LoggerRateLimiter.java
More file actions
31 lines (28 loc) · 1019 Bytes
/
LC359_LoggerRateLimiter.java
File metadata and controls
31 lines (28 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
public class LC359_LoggerRateLimiter {
HashMap<String, Integer> map;
/** Initialize your data structure here. */
public LC359_LoggerRateLimiter() {
map = 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(!map.containsKey(message)){
map.put(message, timestamp);
return true;
}else{
if(timestamp >= map.get(message) + 10){
map.put(message, timestamp);
return true;
}
}
return false;
}
}
/**
* Your Logger object will be instantiated and called as such:
* LC359_LoggerRateLimiter obj = new LC359_LoggerRateLimiter();
* boolean param_1 = obj.shouldPrintMessage(timestamp,message);
*/