C++
Java
Python
Python3
C
C#
JavaScript
Ruby
Swift
Go
Scala
Kotlin
Rust
PHP
TypeScript
Racket
Erlang
Elixir
Dart
monokai
ambiance
chaos
chrome
cloud9_day
cloud9_night
cloud9_night_low_color
clouds
clouds_midnight
cobalt
crimson_editor
dawn
dracula
dreamweaver
eclipse
github
github_dark
gob
gruvbox
gruvbox_dark_hard
gruvbox_light_hard
idle_fingers
iplastic
katzenmilch
kr_theme
kuroir
merbivore
merbivore_soft
mono_industrial
nord_dark
one_dark
pastel_on_dark
solarized_dark
solarized_light
sqlserver
terminal
textmate
tomorrow
tomorrow_night
tomorrow_night_blue
tomorrow_night_bright
tomorrow_night_eighties
twilight
vibrant_ink
xcode
上次编辑到这里,代码来自缓存 点击恢复默认模板
class MovingAverage {
public:
/** Initialize your data structure here. */
MovingAverage(int size) {
}
double next(int val) {
}
};
/**
* Your MovingAverage object will be instantiated and called as such:
* MovingAverage* obj = new MovingAverage(size);
* double param_1 = obj->next(val);
*/
运行代码
提交
python3 解法, 执行用时: 100 ms, 内存消耗: 18.3 MB, 提交时间: 2022-05-27 15:36:06
class MovingAverage:
def __init__(self, size: int):
"""
Initialize your data structure here.
"""
self.nums = []
self.size = size
def next(self, val: int) -> float:
self.nums.append(val)
if len(self.nums) > self.size:
self.nums = self.nums[1:]
return sum(self.nums) / len(self.nums)
# Your MovingAverage object will be instantiated and called as such:
# obj = MovingAverage(size)
# param_1 = obj.next(val)