#703
Kth Largest Element in a Stream
pupil · 425 · lc easy +25 · 60.7% accepted · 6,401 likes · top 60%
Description
Design a class that tracks the kth largest value in a dynamic data stream in real time.
Implement the KthLargest class:
- KthLargest(int k, int[] nums) Initializes the object with rank k and an initial set of values nums.
- int add(int val) Inserts val into the stream and returns the current kth largest value.
Code
1
2
3
4
5
6
7
8
9
10
11
12