Java Map solution beats 99.63% of solutions


  • 0
    X
    
        Map<String, Integer> map;
        /** Initialize your data structure here. */
        public Logger() {
             map = new HashMap<>();
        }
    
        public boolean shouldPrintMessage(int timestamp, String message) {
            Integer time = map.get(message);        
            if (time == null || timestamp - time >= 10) {
                map.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.