deno.land / x / masx200_leetcode_test@10.6.5 / qIsx9U / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
export default class MovingAverage { #queue: number[]; #size: number; #sum: number; constructor(size: number) { if (size < 1) throw Error("size invalid"); this.#queue = []; this.#size = size; this.#sum = 0; }
next(val: number): number { this.#queue.push(val); this.#sum += val;
while (this.#queue.length > this.#size) { const first = this.#queue.shift(); if (first) { this.#sum -= first; } }
return this.#sum / this.#queue.length; }}
masx200_leetcode_test

Version Info

Tagged at
a year ago