We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent deca0e5 commit a35da60Copy full SHA for a35da60
kotlin/0703-kth-largest-element-in-a-stream.kt
@@ -1,18 +1,16 @@
1
-class KthLargest(k: Int, nums: IntArray) {
2
- val minHeap = PriorityQueue<Int>{ a: Int, b: Int ->
3
- a - b
4
- }
5
- var k = Integer.MIN_VALUE
+ class KthLargest(val k: Int, val nums: IntArray) {
+ val minHeap = PriorityQueue<Int>()
+
6
init{
7
- this.k = k
8
- for(num in nums)
+ for (num in nums)
9
minHeap.add(num)
10
- while(minHeap.size > k)
+ while (minHeap.size > k)
11
minHeap.poll()
12
}
13
fun add(`val`: Int): Int {
14
minHeap.add(`val`)
15
- if(minHeap.size > k)
+ if (minHeap.size > k)
16
17
return minHeap.peek()
18
0 commit comments