Skip to content

Commit 5a52881

Browse files
authored
Update README.md
1 parent 781602e commit 5a52881

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

solution/0700-0799/0703.Kth Largest Element in a Stream/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,25 +352,34 @@ class MinHeap {
352352
#### TypeScript
353353

354354
```ts
355-
export class KthLargest {
355+
class KthLargest {
356356
#pq = new MinPriorityQueue();
357357
#k = 0;
358358

359359
constructor(k: number, nums: number[]) {
360360
this.#k = k;
361361
for (const x of nums) {
362362
this.#pq.enqueue(x);
363-
if (this.#pq.size() > k) this.#pq.dequeue();
363+
if (this.#pq.size() > k) {
364+
this.#pq.dequeue();
365+
}
364366
}
365367
}
366368

367369
add(val: number): number {
368370
this.#pq.enqueue(val);
369-
if (this.#pq.size() > this.#k) this.#pq.dequeue();
370-
371+
if (this.#pq.size() > this.#k) {
372+
this.#pq.dequeue();
373+
}
371374
return this.#pq.front().element;
372375
}
373376
}
377+
378+
/**
379+
* Your KthLargest object will be instantiated and called as such:
380+
* var obj = new KthLargest(k, nums)
381+
* var param_1 = obj.add(val)
382+
*/
374383
```
375384

376385
<!-- tabs:end -->

0 commit comments

Comments
 (0)