346.Moving-Average-from-Data-Stream
346. Moving Average from Data Stream
题目地址
https://leetcode.com/problems/moving-average-from-data-stream/
题目描述
Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.
Example:
MovingAverage m = new MovingAverage(3);
m.next(1) = 1
m.next(10) = (1 + 10) / 2
m.next(3) = (1 + 10 + 3) / 3
m.next(5) = (10 + 3 + 5) / 3代码
Approach #1 Array or List
Approach #2 Double-ended Queue
Approach #3 Circular Queue with array
Last updated
Was this helpful?