Skip to content

Commit b5d34d2

Browse files
committed
Kotlin: 215. Kth Largest Element in Array
1 parent fd291b7 commit b5d34d2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: kotlin/215-Kth-Largest-Element-In-Array.kt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
fun findKthLargest(nums: IntArray, k: Int): Int {
3+
val heap = PriorityQueue<Int>()
4+
5+
for (num in nums) {
6+
heap.add(num)
7+
8+
if (heap.size > k)
9+
heap.poll()
10+
}
11+
12+
return heap.peek()
13+
}
14+
}

0 commit comments

Comments
 (0)