Skip to content

Commit b13f491

Browse files
committed
Update index.ts
1 parent 019cf08 commit b13f491

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

finding-mk-average/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { reverseInOrderIterator } from "../dinner-plate-stacks/reverseInOrderIterator.ts";
22
import { InOrderIterator } from "./InOrderIterator.ts";
33
import { MultiRedBlackTree } from "./MultiRedBlackTree.ts";
4-
4+
import { Deque } from "https://esm.sh/@datastructures-js/deque@1.0.4/";
55
class MKAverage {
66
total = 0;
77
m: number;
88
k: number;
9-
queue = new Array<number>();
9+
queue = new Deque<number>();
1010
count = 0;
1111

1212
tree = new MultiRedBlackTree<number>((a, b) => a - b);
@@ -16,7 +16,7 @@ class MKAverage {
1616
}
1717

1818
addElement(num: number) {
19-
this.queue.push(num);
19+
this.queue.pushBack(num);
2020

2121
this.tree.insert(num);
2222
this.total += num;
@@ -33,9 +33,9 @@ class MKAverage {
3333
// }
3434
// console.log(JSON.stringify(temp));
3535
// }
36-
if (this.queue.length === this.m + 1) {
37-
const willBeDelete: number = this.queue[0];
38-
this.queue.shift();
36+
if (this.queue.size() === this.m + 1) {
37+
const willBeDelete: number = this.queue.front();
38+
this.queue.popFront();
3939
// console.log("deleteElement", willBeDelete);
4040
this.total -= willBeDelete;
4141
this.tree.remove(willBeDelete);

0 commit comments

Comments
 (0)