Skip to main content

359. Logger Rate Limiter

https://leetcode.com/problems/logger-rate-limiter/

Level: Easy

O(1)\mathcal{O}(1) Time

class Logger:

def __init__(self):
self.message_cache = dict()

def shouldPrintMessage(self, timestamp: int, message: str) -> bool:
if message in self.message_cache:
t = self.message_cache[message]
if t + 10 > timestamp:
# self.message_cache[message] = timestamp
return False
del self.message_cache[message]
self.message_cache[message] = timestamp
return True