← 返回 atlassian 的题目列表Moving Window Average
类型:online_judge
Design a data structure to calculate the moving average of a sliding window.
Implement a class with the following operation:
next(val): Add the element val and return the average of all elements in the window.
Assume the window size is fixed.
Example
Input
next(1)
next(2)
next(3)
Output
1
1.5
2