LeetCode/LeetCode75

[LeetCode 75] Easy - 933. Number of Recent Calls

hyunkookim 2024. 11. 14. 17:07

933. Number of Recent Calls

 

import collections
class RecentCounter:

    def __init__(self):
        self.q = collections.deque()
        self.q_len = 0

    def ping(self, t: int) -> int:
        self.q.append(t)
        self.q_len +=1
        while self.q[0] < t-3000:
            self.q.popleft()
            self.q_len -=1
        return self.q_len 


# Your RecentCounter object will be instantiated and called as such:
# obj = RecentCounter()
# param_1 = obj.ping(t)