Kth Largest Data Stream
Design a class to find thekth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.
Your KthLargest
class will have a constructor which accepts an integerk
and an integer arraynums
, which contains initial elements from the stream. For each call to the methodKthLargest.add
, return the element representing the kth largest element in the stream.
Example
Code
Last updated