1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00
LeetCode/rs/kth-largets-element-in-an-array.rs

14 lines
273 B
Rust
Raw Normal View History

use std::collections::BinaryHeap;
impl Solution {
pub fn find_kth_largest(nums: Vec<i32>, k: i32) -> i32 {
let mut h: BinaryHeap<i32> = nums.into_iter().collect();
for _ in 0..k - 1 {
h.pop();
}
*h.peek().unwrap()
}
}