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 @@ -351,25 +351,34 @@ class MinHeap {
351
351
#### TypeScript
352
352
353
353
``` ts
354
- export class KthLargest {
354
+ class KthLargest {
355
355
#pq = new MinPriorityQueue ();
356
356
#k = 0 ;
357
357
358
358
constructor (k : number , nums : number []) {
359
359
this .#k = k ;
360
360
for (const x of nums ) {
361
361
this .#pq .enqueue (x );
362
- if (this .#pq .size () > k ) this .#pq .dequeue ();
362
+ if (this .#pq .size () > k ) {
363
+ this .#pq .dequeue ();
364
+ }
363
365
}
364
366
}
365
367
366
368
add(val : number ): number {
367
369
this .#pq .enqueue (val );
368
- if (this .#pq .size () > this .#k ) this .#pq .dequeue ();
369
-
370
+ if (this .#pq .size () > this .#k ) {
371
+ this .#pq .dequeue ();
372
+ }
370
373
return this .#pq .front ().element ;
371
374
}
372
375
}
376
+
377
+ /**
378
+ * Your KthLargest object will be instantiated and called as such:
379
+ * var obj = new KthLargest(k, nums)
380
+ * var param_1 = obj.add(val)
381
+ */
373
382
```
374
383
375
384
<!-- tabs:end -->
You can’t perform that action at this time.
0 commit comments