[leetcode]Moving Average from Data Stream
Posted 阿牧遥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[leetcode]Moving Average from Data Stream相关的知识,希望对你有一定的参考价值。
使用了queue
from queue import Queue class MovingAverage: def __init__(self, size: int): """ Initialize your data structure here. """ self.que = Queue() self.size = size self.windowSum = 0 def next(self, val: int) -> float: if self.que.qsize() == self.size: self.windowSum -= self.que.get() self.que.put(val) self.windowSum += val return self.windowSum / self.que.qsize() # Your MovingAverage object will be instantiated and called as such: # obj = MovingAverage(size) # param_1 = obj.next(val)
以上是关于[leetcode]Moving Average from Data Stream的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode-Moving Average from Data Stream
[LeetCode] 346. Moving Average from Data Stream ??????????????????????????????
[leetcode]346. Moving Average from Data Stream滑动窗口平均值