Straight forward Python solution


  • 3
    
    class Logger(object):
    
        def __init__(self):
            """
            Initialize your data structure here.
            """
            self._d = {}
    
        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 in self._d and timestamp - self._d[message] < 10:
                return False
            else:
                self._d[message] = timestamp
                return True
    

Log in to reply
 

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