当前位置:网站首页>【每日一题】剑指 Offer II 041. 滑动窗口的平均值
【每日一题】剑指 Offer II 041. 滑动窗口的平均值
2022-07-17 04:20:00 【爱写Bug的王六六】
题目:
给定一个整数数据流和一个窗口大小,根据该滑动窗口的大小,计算滑动窗口里所有数字的平均值。
实现 MovingAverage 类:
- MovingAverage(int size) 用窗口大小 size 初始化对象。
- double next(int val) 成员函数 next 每次调用的时候都会往滑动窗口增加一个整数,请计算并返回数据流中最后 size 个值的移动平均值,即滑动窗口里所有数字的平均值。
输入:
inputs = [“MovingAverage”, “next”, “next”, “next”, “next”]
inputs = [[3], [1], [10], [3], [5]]
输出: [null, 1.0, 5.5, 4.66667, 6.0]解释:
MovingAverage movingAverage = new MovingAverage(3);
movingAverage.next(1); // 返回 1.0 = 1 / 1
movingAverage.next(10); // 返回5.5 = (1 + 10) / 2
movingAverage.next(3); // 返回 4.66667 = (1 + 10 + 3) / 3
movingAverage.next(5); // 返回 6.0 = (10 + 3 + 5) / 3
双端队列
根据题意,我们可以使
边栏推荐
- Hello World driver
- Wechat e-book reading of small program graduation project (4) opening report
- The adaptation of go language under windows10:vscode
- Data interaction between avframe\avpacket and itself in ffmpeg
- C # use this keyword to concatenate constructor to call method
- B+ tree stored procedures, triggers, substring and substr, and truncate and delete
- Machine learning 09: unsupervised learning
- VirtualLab基础实验教程-7.偏振(3)
- Technical writing guide for programmers to leave work early
- Niuke 2021 training League warm-up training match interstellar love (and search Collection)
猜你喜欢

ospf防环

PowerDesigner显示Comment注释

Intel experts share: how to program efficiently on XPU architecture? Zhiqiang Research Institute

T + 0 to t + 1! The quick redemption amount is reduced to 10000! Another bank adjusted the rules for the application and redemption of cash wealth management products

Touchid and faceid~2

Nearly 90% of servers can be saved, but the anti fraud efficiency has increased significantly. Why is PayPal's plan to break the "Ai memory wall" so cost-effective?

HCR慧辰北坡而行,一只游入数字营销服务的巨兽

使用kaggle跑李宏毅机器学习作业

MySQL中判断和向下取整的使用场景和用法

Live broadcast of cloud intelligence face to face is waiting for you: computing power redefines productivity
随机推荐
Wkwebview white screen
06 Maui, WPF uses MVVM toolkit framework to build MVVM program
B+树存储过程、触发器、Substring和substr的区别及Truncate和Delete的区别
ffmpeg中AVFrame\AVPacket与自己的数据交互
sql中的substr与substring函数用法
结构体通过成员变量获取主结构体地址(struct)
Mature threads should know how to refuse
OSPF comprehensive experiment
MAUI 框架入门学习05 MVVM数据模型理解
51 single chip microcomputer to find out the input mode
What does the project set price mean?
基于JIRA7.9.2定制修改
[wechat applet] super easy to understand conditional rendering and list rendering
HCR慧辰北坡而行,一只游入数字营销服务的巨兽
模拟服务器进行请求
STM32——定时器系列(二)通用定时器
Deconstruction of typescript array / object / string / function parameters
Machine learning 11: cost sensitive learning
STM32 - timer series (II) general timer
mysql中的视图、触发器和存储过程