当前位置:网站首页>Sword finger offer II 041. Average value of sliding window
Sword finger offer II 041. Average value of sliding window
2022-07-27 13:48:00 【anieoo】
Original link : The finger of the sword Offer II 041. Average value of sliding window
solution
class MovingAverage {
public:
/** Initialize your data structure here. */
int wsize; // Window size
vector<int> window;
int kth = 0;
int flag = 0;
MovingAverage(int size) {
wsize = size;
window = vector<int> (size);
}
double next(int val) {
double res = 0; // Define the return value
kth %= wsize;
window[kth] = val;
kth++;
flag++;
for(auto &x : window) res += x;
return flag >= wsize? res / wsize : res / kth;
}
};
/**
* Your MovingAverage object will be instantiated and called as such:
* MovingAverage* obj = new MovingAverage(size);
* double param_1 = obj->next(val);
*/边栏推荐
- Cute image classification -- a general explanation of the article "what are the common flops in CNN model?"
- How to maintain slip ring equipment
- Jianzhi offer 07 rebuild binary tree -- construct binary tree from middle order and post order traversal sequence
- shell环境变量以及set,env,export的区别
- 纵横靶场-图片的奥秘
- 【每日一题】1206. 设计跳表
- 看看有没有你,各赛区入围名单
- For.. of can be used to traverse which data
- SCI论文写作
- [introduction to C language] zzulioj 1021-1025
猜你喜欢

期货手续费标准和保证金比例

Fiddler抓包工具+夜神模拟器

opencv图像的缩放平移及旋转

Design of network abnormal traffic analysis system

MySQL startup options and configuration files

小程序毕设作品之微信校园洗衣小程序毕业设计成品(5)任务书

SQL教程之 SQL 聚合函数入门教程

Install redis and graphical client under MacOS

Li Hang, director of ByteDance AI Lab: past, present and future of language model

Conditions and procedures of futures account opening
随机推荐
evutil_make_internal_pipe_: pipe: Too many open files
Interviewers often ask: how to set up a "message queue" and "delayed message queue"?
Egg swagger doc graphic verification code solution
Deliver temperature with science and technology, vivo appears at the digital China Construction Summit
Common types of electric slip rings
Double material first!
将目标检测大尺寸图片裁剪成固定尺寸图片
使用RecyclerView,实现列表左滑菜单
leetcode——83,24;机器学习——神经网络
Data enhancement in image processing
Construction and application of industrial knowledge atlas (2): representation and modeling of commodity knowledge
SCI thesis writing
How to fix the slip ring
字节跳动 AI Lab 总监李航:语言模型的过去、现在和未来
Futures Commission Standard and margin ratio
C# FTP增、删、改、查、创建多级目录、自动重连、切换目录
在“元宇宙空间”UTONMOS将打开虚实结合的数字世界
JS 模块、闭包应用
图像特征及提取
网络异常流量分析系统设计