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 d701c5e commit d60e693Copy full SHA for d60e693
src/main/kotlin/leetcode/kth-largest-element-in-an-array/Solution.kt
@@ -0,0 +1,14 @@
1
+package leetcode.`kth-largest-element-in-an-array`
2
+
3
+import java.util.PriorityQueue
4
5
+class Solution {
6
+ fun findKthLargest(nums: IntArray, k: Int): Int {
7
+ val heap = PriorityQueue<Int> { o1, o2 -> o2 - o1 }
8
+ nums.forEach { heap.add(it) }
9
+ repeat(k - 1){
10
+ heap.poll()
11
+ }
12
+ return heap.poll()
13
14
+}
0 commit comments