We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 58ce124 commit f90ae36Copy full SHA for f90ae36
Python/number-of-recent-calls.py
@@ -0,0 +1,20 @@
1
+# Time: O(1) on average
2
+# Space: O(w), w means the size of the last milliseconds.
3
+
4
+import collections
5
6
7
+class RecentCounter(object):
8
9
+ def __init__(self):
10
+ self.__q = collections.deque()
11
12
+ def ping(self, t):
13
+ """
14
+ :type t: int
15
+ :rtype: int
16
17
+ self.__q.append(t)
18
+ while self.__q[0] < t-3000:
19
+ self.__q.popleft()
20
+ return len(self.__q)
0 commit comments