Skip to content

Commit da34f36

Browse files
edit 359
1 parent fa50b53 commit da34f36

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Your ideas/fixes/algorithms are more than welcome!
233233
|362|[Design Hit Counter](https://leetcode.com/problems/design-hit-counter/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_362.java)| O(1) amortized|O(k) | Medium| Design
234234
|361|[Bomb Enemy](https://leetcode.com/problems/bomb-enemy/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_361.java)| O(?)|O(?) | Medium|
235235
|360|[Sort Transformed Array](https://leetcode.com/problems/sort-transformed-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_360.java)| O(n)|O(1) | Medium| Two Pointers, Math
236-
|359|[Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter/)|[Solution](../master/src/main/java/com/fishercoder/solutions/LoggerRateLimiter.java)| amortized O(1)|O(k) | Easy| HashMap
236+
|359|[Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_359.java)| amortized O(1)|O(k) | Easy| HashMap
237237
|358|[Rearrange String k Distance Apart](https://leetcode.com/problems/rearrange-string-k-distance-apart/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_358.java)| O(n)|O(n) | Hard| HashMap, Heap, Greedy
238238
|357|[Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_357.java)| O(?)|O(?) | Medium|
239239
|356|[Line Reflection](https://leetcode.com/problems/line-reflection/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_356.java)| O(n)|O(n) | Medium| HashSet

src/main/java/com/fishercoder/solutions/LoggerRateLimiter.java renamed to src/main/java/com/fishercoder/solutions/_359.java

+24-21
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,35 @@ Given a message and a timestamp (in seconds granularity), return true if the mes
3131
3232
// logging string "foo" at timestamp 11
3333
logger.shouldPrintMessage(11,"foo"); returns true;*/
34-
public class LoggerRateLimiter {
34+
public class _359 {
3535

36-
}
36+
class Logger {
3737

38-
class Logger {
39-
40-
private Map<String, Integer> map;
41-
private Set<String> set;
38+
private Map<String, Integer> map;
39+
private Set<String> set;
4240

43-
/** Initialize your data structure here. */
44-
public Logger() {
45-
map = new HashMap<String, Integer>();
46-
set = new HashSet<String>();
47-
}
48-
49-
/** Returns true if the message should be printed in the given timestamp, otherwise returns false. The timestamp is in seconds granularity. */
50-
public boolean shouldPrintMessage(int timestamp, String message) {
51-
if(!set.contains(message)) {
52-
map.put(message, timestamp);
53-
set.add(message);
54-
return true;
55-
} else {
56-
if(timestamp - map.get(message) < 10) return false;
57-
else{
41+
/**
42+
* Initialize your data structure here.
43+
*/
44+
public Logger() {
45+
map = new HashMap<String, Integer>();
46+
set = new HashSet<String>();
47+
}
48+
49+
/**
50+
* Returns true if the message should be printed in the given timestamp, otherwise returns false. The timestamp is in seconds granularity.
51+
*/
52+
public boolean shouldPrintMessage(int timestamp, String message) {
53+
if (!set.contains(message)) {
5854
map.put(message, timestamp);
55+
set.add(message);
5956
return true;
57+
} else {
58+
if (timestamp - map.get(message) < 10) return false;
59+
else {
60+
map.put(message, timestamp);
61+
return true;
62+
}
6063
}
6164
}
6265
}

0 commit comments

Comments
 (0)