当前位置:网站首页>2022.7.16-----leetcode.剑指offer.041
2022.7.16-----leetcode.剑指offer.041
2022-07-17 10:23:00 【路Lu727】
int n;
int sum;
Deque<Integer> q;
/** Initialize your data structure here. */
public MovingAverage(int size) {
n=size;
sum=0;
q=new ArrayDeque<>();
}
public double next(int val) {
if(q.size()<n){
q.add(val);
sum+=val;
return (double)sum/q.size();
}else{
sum-=q.poll();
q.add(val);
sum+=val;
return (double) sum/n;
}
}边栏推荐
猜你喜欢

C language compilation process

将视频格式转换为gif图片格式

Un7.16: how to deploy projects on code cloud and invite team members?

面試題-給::memcpy函數設計測試用例

Day 6 training

KNN classifier

How to build your own cloud database in docker

Express

Simple third-party component log desensitization

Resolve the applicationeventmulticast not initialized - call 'refresh' before multicast events exception
随机推荐
ArrayList底层分析
Etcd database source code analysis - initialize etcdserver structure
LDA分类器
面试题-给::memcpy函数设计测试用例
MySQL view
【C语言】void类型和void*指针类型
codeforces每日5题(均1500)-第十七天
Leetcode 197 Rising temperature (July 16, 2022)
mysqldump全备恢复到新另一个实例然后再执行flush privileges的情况分析
DuiLib 实现tooltip自定义鼠标提示窗口
how to use culasLt
R语言data.table导入数据实战:data.table使用dcast.data.table函数实现透视表(pivot table)
银河麒麟v10-arm版离线安装Portainer
组件间的相互访问
C语言力扣第25题之k个一组反转链表。多指针遍历
Target detection model size calculation, model complexity (parameter conversion formula)
KNN分類器
【C语言】数组知识点总结
Encapsulation API, request interception, response interception, authentication timeliness
Flink小知识--任务调度slot的配置 slotSharingGroup