Java HashMap solution


  • 0
    Q
    public class Logger {
        HashMap<String, Integer> map;
        public Logger() {
            map = new HashMap<String, Integer>();
        }
        public boolean shouldPrintMessage(int timestamp, String msg) {
            Integer preTime = map.get(msg);
            if(preTime == null || (timestamp - preTime >= 10)){
                map.put(msg, 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.