Deque vs Queue Speed
问题 I was working on a problem on LeetCode (Here). When I finished the problem, I came up with: class MovingAverage { std::deque<int> numsToAverage; int maxSize; int currentTotal; public: /** Initialize your data structure here. */ MovingAverage(int size) { maxSize = size; currentTotal = 0; } double next(int val) { currentTotal += val; numsToAverage.push_back(val); if (numsToAverage.size() > maxSize) { currentTotal -= numsToAverage[0]; numsToAverage.pop_front(); } return (double)currentTotal /