mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
rs: add “215. Kth Largest Element in an Array”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
0c96d36b10
commit
9cfd3567be
1 changed files with 13 additions and 0 deletions
13
rs/kth-largets-element-in-an-array.rs
Normal file
13
rs/kth-largets-element-in-an-array.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
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()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue