File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
solution/0700-0799/0703.Kth Largest Element in a Stream Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -352,25 +352,34 @@ class MinHeap {
352
352
#### TypeScript
353
353
354
354
``` ts
355
- export class KthLargest {
355
+ class KthLargest {
356
356
#pq = new MinPriorityQueue ();
357
357
#k = 0 ;
358
358
359
359
constructor (k : number , nums : number []) {
360
360
this .#k = k ;
361
361
for (const x of nums ) {
362
362
this .#pq .enqueue (x );
363
- if (this .#pq .size () > k ) this .#pq .dequeue ();
363
+ if (this .#pq .size () > k ) {
364
+ this .#pq .dequeue ();
365
+ }
364
366
}
365
367
}
366
368
367
369
add(val : number ): number {
368
370
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
+ }
371
374
return this .#pq .front ().element ;
372
375
}
373
376
}
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
+ */
374
383
```
375
384
376
385
<!-- tabs:end -->
You can’t perform that action at this time.
0 commit comments