classMovingAverage:def__init__(self, size:int):"""Initialize your data structure here."""self.size=size+1self.front=0self.rear=0self.queue=[Nonefor _ inrange(size+1)]self.sum=0defnext(self, val:int)->float:# 满了if(self.rear+1)%self.size==self.front:self.front=(self.front+1)%self.sizeself.sum-=self.queue[self.front]self.rear=(self.rear+1)%self.sizeself.queue[self.rear]=valself.sum+=valreturn1.0*self.sum/(self.size-1)else:self.rear=self.rear+1self.queue[self.rear]=valself.sum+=valreturn1.0*self.sum/(self.rear-self.front)# Your MovingAverage object will be instantiated and called as such:# obj = MovingAverage(size)# param_1 = obj.next(val)