number

简述

求3000ms前到现在的ping数。
number-of-recent-calls
英文 中文

收获

1.用list来理解collections.deque()
2.
https://docs.python.org/3/library/collections.html
3.廖雪峰collections

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class :

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

def ping(self, t):
"""
:type t: int
:rtype: int
"""
self.q.append(t)
while self.q[0] < t-3000:
self.q.popleft()
return len(self.q)




# obj = RecentCounter()
# param_1 = obj.ping(t)