forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_359.java
44 lines (38 loc) · 1.25 KB
/
_359.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class _359 {
public static class Solution1 {
class Logger {
private Map<String, Integer> map;
private Set<String> set;
/**
* Initialize your data structure here.
*/
public Logger() {
map = new HashMap<String, Integer>();
set = new HashSet<String>();
}
/**
* Returns true if the message should be printed in the given timestamp, otherwise returns
* false. The timestamp is in seconds granularity.
*/
public boolean shouldPrintMessage(int timestamp, String message) {
if (!set.contains(message)) {
map.put(message, timestamp);
set.add(message);
return true;
} else {
if (timestamp - map.get(message) < 10) {
return false;
} else {
map.put(message, timestamp);
return true;
}
}
}
}
}
}