[practice JS] a plain solution...


  • 0
    M

    what? JS is not supported in this problem... ok...
    cannot stop me spamming posts : ]

    class Logger(object):
    
        def __init__(self):
            """
            Initialize your data structure here.
            """
            self.messageTimestampMap = {}
            
            
        def shouldPrintMessage(self, timestamp, message):
            """
            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.
            :type timestamp: int
            :type message: str
            :rtype: bool
            """
            if message not in self.messageTimestampMap:
                self.messageTimestampMap[message] = timestamp;
                return True;
            else:
                if (timestamp - self.messageTimestampMap[message] >= 10):
                    self.messageTimestampMap[message] = timestamp;
                    return True;
                else:
                    return False;
    
    # Your Logger object will be instantiated and called as such:
    # obj = Logger()
    # param_1 = obj.shouldPrintMessage(timestamp,message)
    

Log in to reply
 

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