classLogger:def__init__(self):self.ts={}defshouldPrintMessage(self,timestamp:int,message:str)->bool:t=self.ts.get(message,0)ift>timestamp:returnFalseself.ts[message]=timestamp+10returnTrue# Your Logger object will be instantiated and called as such:# obj = Logger()# param_1 = obj.shouldPrintMessage(timestamp,message)
1 2 3 4 5 6 7 8 9101112131415161718192021
classLogger{privateMap<String,Integer>ts=newHashMap<>();publicLogger(){}publicbooleanshouldPrintMessage(inttimestamp,Stringmessage){intt=ts.getOrDefault(message,0);if(timestamp<t){returnfalse;}ts.put(message,timestamp+10);returntrue;}}/** * Your Logger object will be instantiated and called as such: * Logger obj = new Logger(); * boolean param_1 = obj.shouldPrintMessage(timestamp,message); */
1 2 3 4 5 6 7 8 910111213141516171819202122
classLogger{public:Logger(){}boolshouldPrintMessage(inttimestamp,stringmessage){if(ts.contains(message)&&ts[message]>timestamp){returnfalse;}ts[message]=timestamp+10;returntrue;}private:unordered_map<string,int>ts;};/** * Your Logger object will be instantiated and called as such: * Logger* obj = new Logger(); * bool param_1 = obj->shouldPrintMessage(timestamp,message); */
1 2 3 4 5 6 7 8 9101112131415161718192021
typeLoggerstruct{tsmap[string]int}funcConstructor()Logger{returnLogger{ts:make(map[string]int)}}func(this*Logger)ShouldPrintMessage(timestampint,messagestring)bool{ift,ok:=this.ts[message];ok&×tamp<t{returnfalse}this.ts[message]=timestamp+10returntrue}/** * Your Logger object will be instantiated and called as such: * obj := Constructor(); * param_1 := obj.ShouldPrintMessage(timestamp,message); */
/** * Initialize your data structure here. */varLogger=function(){this.limiter={};};/** * Returns true if the message should be printed in the given timestamp, otherwise returns false. If this method returns false, the message will not be printed. The timestamp is in seconds granularity. * @param {number} timestamp * @param {string} message * @return {boolean} */Logger.prototype.shouldPrintMessage=function(timestamp,message){constt=this.limiter[message]||0;if(t>timestamp){returnfalse;}this.limiter[message]=timestamp+10;returntrue;};/** * Your Logger object will be instantiated and called as such: * var obj = new Logger() * var param_1 = obj.shouldPrintMessage(timestamp,message) */