Skip to content

Commit c9097bb

Browse files
authored
Update Solution.ts
1 parent 5a52881 commit c9097bb

File tree

1 file changed

+13
-4
lines changed
  • solution/0700-0799/0703.Kth Largest Element in a Stream

1 file changed

+13
-4
lines changed
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
export class KthLargest {
1+
class KthLargest {
22
#pq = new MinPriorityQueue();
33
#k = 0;
44

55
constructor(k: number, nums: number[]) {
66
this.#k = k;
77
for (const x of nums) {
88
this.#pq.enqueue(x);
9-
if (this.#pq.size() > k) this.#pq.dequeue();
9+
if (this.#pq.size() > k) {
10+
this.#pq.dequeue();
11+
}
1012
}
1113
}
1214

1315
add(val: number): number {
1416
this.#pq.enqueue(val);
15-
if (this.#pq.size() > this.#k) this.#pq.dequeue();
16-
17+
if (this.#pq.size() > this.#k) {
18+
this.#pq.dequeue();
19+
}
1720
return this.#pq.front().element;
1821
}
1922
}
23+
24+
/**
25+
* Your KthLargest object will be instantiated and called as such:
26+
* var obj = new KthLargest(k, nums)
27+
* var param_1 = obj.add(val)
28+
*/

0 commit comments

Comments
 (0)