Skip to content

Commit d60e693

Browse files
committed
1 parent d701c5e commit d60e693

File tree

1 file changed

+14
-0
lines changed
  • src/main/kotlin/leetcode/kth-largest-element-in-an-array

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)