Clean HashMap solution


  • 0
    M
    public class Logger {
        Map<String, Integer> lastPrintTime;
       
        public Logger() {
            lastPrintTime = new HashMap<String, Integer>();
        }
        
        public boolean shouldPrintMessage(int timestamp, String message) {
            if(lastPrintTime.containsKey(message)) {
                if(timestamp - lastPrintTime.get(message) < 10){
                    return false;
                }
            }
            
            lastPrintTime.put(message, timestamp);
            
            return true;
        }
    }
    

Log in to reply
 

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