Java HashMap Solution


  • 0
    T
    Map<String, Integer> hmap;
    public Logger() {
        this.hmap = new HashMap<String, Integer>();
    }
    public boolean shouldPrintMessage(int timestamp, String message) {
        if (!hmap.containsKey(message) || timestamp - hmap.get(message) > 9) {
            hmap.put(message, timestamp);
            return true;
        }
        return false;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.