Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 614 Bytes

Question_359.md

File metadata and controls

28 lines (21 loc) · 614 Bytes

LeetCode Records - Question 359 Logger Rate Limiter

Attempt 1: Use a HashMap

class Logger {

    private final Map<String, Integer> map;

    public Logger() {
        map = new HashMap<>();
    }

    public boolean shouldPrintMessage(int timestamp, String message) {
        Integer prevTimestamp = map.get(message);
        if (prevTimestamp != null && timestamp < prevTimestamp + 10) {
            return false;
        }
        
        map.put(message, timestamp);
        return true;
    }
}
  • Runtime: 29 ms (Beats: 99.52%)
  • Memory: 55.54 MB (Beats: 13.56%)