题目链接
思路
队列设计基础题
代码
class MovingAverage {
private Integer currentSum = 0;
private Queue<Integer> queue = new LinkedList<>();
private int size;
public MovingAverage(int size) {
this.size = size;
}
public double next(int val) {
queue.offer(val);
currentSum += val;
if(queue.size() > this.size){
currentSum -= queue.remove();
}
return 1.0 * currentSum / queue.size();
}
}
标签:currentSum,val,int,private,queue,346,数据流,LeetCode,size
From: https://www.cnblogs.com/shixuanliu/p/17064494.html