LeetCode/rs/kth-largets-element-in-an-array.rs
Matej Focko 9cfd3567be
rs: add “215. Kth Largest Element in an Array”
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-11 23:44:36 +01:00

13 lines
273 B
Rust

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()
}
}