Advertisement
smj007

Untitled

Mar 5th, 2024
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. class HitCounter:
  2.  
  3.     def __init__(self):
  4.         self.counter = deque()
  5.  
  6.     def hit(self, timestamp: int) -> None:
  7.         self.counter.append(timestamp)
  8.        
  9.     def getHits(self, timestamp: int) -> int:
  10.  
  11.         while len(self.counter) > 0 and self.counter[0] <= timestamp - 300:
  12.             self.counter.popleft()
  13.  
  14.         return len(self.counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement