Python using Dict


  • 0
    class Logger(object):
    
        def __init__(self):
            self.h = {}
                
        def shouldPrintMessage(self, timestamp, message):
            if not message in self.h or timestamp - self.h[message] >= 10:
                self.h[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.