day11-队列练习题力扣933

在这里插入图片描述
思路:
在这里插入图片描述
伪代码:
实现一个类,需要有构造函数,其次还有个ping方法

func():  #  构造函数
    Q = queue()
ping(t): -> int
    Q.add(t)
    while(len(Q) > 0 and t - Q.peek() > 3000):
        Q.pop()
    return len(Q)

Python代码:

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

def ping(self, t: int) -> int:
    self.q.append(t)
    while len(self.q)>0 and t - self.q[0] >3000:
        self.q.popleft()
    return len(self.q)

版权声明:本文为weixin_45361800原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。