标签:
1 public class Logger { 2 private Map<String, Integer> data; 3 /** Initialize your data structure here. */ 4 public Logger() { 5 data = new HashMap<>(); 6 } 7 8 /** Returns true if the message should be printed in the given timestamp, otherwise returns false. 9 If this method returns false, the message will not be printed. 10 The timestamp is in seconds granularity. */ 11 public boolean shouldPrintMessage(int timestamp, String message) { 12 if (!data.containsKey(message) || timestamp - data.get(message) >= 10) { 13 data.put(message, timestamp); 14 return true; 15 } 16 return false; 17 } 18 } 19 20 /** 21 * Your Logger object will be instantiated and called as such: 22 * Logger obj = new Logger(); 23 * boolean param_1 = obj.shouldPrintMessage(timestamp,message); 24 */
标签:
原文地址:http://www.cnblogs.com/shuashuashua/p/5619852.html