当前位置:网站首页>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);
*/边栏推荐
- eBPF/Ftrace
- 2022年7月24日 暑假第二周训练
- 软考 系统架构设计师 简明教程 | 系统设计
- JS callback function (callback)
- 基于frp实现内网穿透——借助公网服务器实现ssh远程连接内网服务器
- 网络异常流量分析系统设计
- 51: Chapter 5: develop admin management services: 4: develop [add admin account, interface]; (only [user name + password, method]; [@t...] annotation controls transactions; when setting cookies, do yo
- 7.26模拟赛总结
- JS divides the array into two-dimensional arrays according to the specified attribute values
- 【基础知识】~ 集成电路设计流程,以及各阶段所使用的EDA工具
猜你喜欢

Seata's landing practice in ant International Banking

2022年7月24日 暑假第二周训练

小程序毕设作品之微信校园洗衣小程序毕业设计成品(6)开题答辩PPT

滑环使用如何固定

JS divides the array into two-dimensional arrays according to the specified attribute values

Jianzhi offer 07 rebuild binary tree -- construct binary tree from middle order and post order traversal sequence

MFC FTP创建多级文件夹、上传文件到FTP指定目录

Additional: [urlencoder.encode (string to be encoded, "encoding method");] (what is it?; why do we use this to encode when we set values in cookies?) (to be improved...)

小程序毕设作品之微信校园洗衣小程序毕业设计成品(7)中期检查报告

ThinkPHP+宝塔运营环境实现定时任务
随机推荐
egg-swagger-doc 图形验证码解决方案
JS 模块、闭包应用
PCL 常用操作
Set up SSH key based authentication using putty
电滑环的常用类型
Construction and application of industrial knowledge atlas (2): representation and modeling of commodity knowledge
[daily question] 1206. Design jump table
[introduction to C language] zzulioj 1021-1025
Selenium eight elements positioning and relative locator
Figure 8 shows you how to configure SNMP
Intranet penetration based on FRP -- SSH Remote connection to intranet server with the help of public server
Go language series: how to build a go language development environment?
浏览器内核模块组成
What are the precautions for using carbon brushes
【C语言入门】ZZULIOJ 1021-1025
52: Chapter 5: developing admin management services: 5: developing [paging query admin account list, interface]; (swagger's @apiparam(), annotate the method parameters; PageHelper paging plug-in; Inte
JS module, closure application
Common distributed theories (cap, base) and consistency protocols (gosssip, raft)
Fifth, download the PC terminal of personality and solve the problem of being unable to open it
小程序毕设作品之微信校园洗衣小程序毕业设计成品(6)开题答辩PPT