Skip to content

Commit 7e2b961

Browse files
authored
Merge pull request #1141 from MaratKhakim/215-Kth-Largest-kt
Kotlin: 215. Kth Largest Element in Array
2 parents 998e6cd + b5d34d2 commit 7e2b961

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)