当前位置:网站首页>Sword finger offer II 041 Average value of sliding window
Sword finger offer II 041 Average value of sliding window
2022-07-19 11:14:00 【Sasakihaise_】
The finger of the sword Offer II 041. Average value of sliding window

【 analysis 】 Maintain a length of size The two terminal queue , In the absence of size Just add elements before the size , When reach size After size , Just remove the head of the team and add new elements at the end of the team .
class MovingAverage {
// The sliding window 10:10 10
int n;
int t = 0;
double sum = 0;
Deque<Integer> queue = new LinkedList();
/** Initialize your data structure here. */
public MovingAverage(int size) {
n = size;
}
public double next(int val) {
if (t < n) {
t++;
sum += val;
queue.offer(val);
return sum / t;
}
sum -= queue.poll();
queue.offer(val);
sum += val;
return sum / n;
}
}
/**
* Your MovingAverage object will be instantiated and called as such:
* MovingAverage obj = new MovingAverage(size);
* double param_1 = obj.next(val);
*/A few days ago jio Twisted , So I put it for a few days , Now start to make up for the debts you owe before .
边栏推荐
- web安全入门-部署Snort开源IDS/IPS系统
- LeetCode 745. 前缀和后缀搜索
- Mysql索引的类型(单列索引、组合索引 btree索引 聚簇索引等)
- Introduction to sap appgyver
- Some methods of early MCU encryption [get data in the comment area]
- 常用getshell工具的下载
- What should I do if I can't see any tiles on SAP Fiori launchpad?
- LeetCode 558. 四叉树交集
- (1) Learn about MySQL
- Set the interface language of CMD command prompt window to English
猜你喜欢

Evaluation method of machine learning model

Powercli script performance optimization

vulnhub inclusiveness: 1

NVIDIA uses AI to design GPU: the latest H100 has been used, which reduces the chip area by 25% compared with traditional EDA

antd 下拉多选传值到后台做查询操作

Win10的环境变量配置

XSS.haozi.me刷题

早期单片机加密的一些方法 【评论区领取资料】
![[leetcode weekly replay] 302 weekly 20220717](/img/38/446db9b4755f8b30f9887faede7e95.png)
[leetcode weekly replay] 302 weekly 20220717

Mysql索引的类型(单列索引、组合索引 btree索引 聚簇索引等)
随机推荐
Un modèle de détection par défaut basé sur le réseau neuronal évolutif rapide dans le contrôle de la qualité des produits - lire les notes
论文笔记:Mind the Gap An Experimental Evaluation of Imputation ofMissing Values Techniques in TimeSeries
Opencv programming: opencv3 X trains its own classifier
Codeforces - 587e (linear basis + segment tree + difference)
Environment variable configuration of win10
How can enterprise telecommuting be more efficient?
玩转CANN目标检测与识别一站式方案
E-commerce sales data analysis and prediction (date data statistics, daily statistics, monthly statistics)
Over fitting and under fitting
Deep learning for generic object detection: a survey
Antd drop-down multiple options to transfer values to the background for query operations
Pytoch learning record 2 linear regression (tensor, variable)
Goldfish rhca memoirs: cl210 describes the openstack control plane -- identify the overcloud control platform service + chapter experiment
High number_ Chapter 1 space analytic geometry and vector algebra__ Distance from point to plane
Loj#2324-「清华集训 2017」小 Y 和二叉树
Openfoam heat flow boundary condition
LeetCode 2331. Calculate the value of Boolean binary tree (tree traversal)
Beego framework realizes file upload + seven cattle cloud storage
A simple output method of promise object to the result in nodejs (it is recommended to use the asynchronous ultimate scheme async+await)
After summarizing the surface based knowledge of the database