10000 Create December-12.rs · Hunterdii/Leetcode-POTD@96a387a · GitHub
[go: up one dir, main page]

Skip to content

Commit 96a387a

Browse files
authored
Create December-12.rs
1 parent 9a2d694 commit 96a387a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::collections::BinaryHeap;
2+
3+
impl Solution {
4+
pub fn pick_gifts(gifts: Vec<i32>, k: i32) -> i64 {
5+
let mut max_heap: BinaryHeap<i32> = BinaryHeap::from(gifts);
6+
for _ in 0..k {
7+
if let Some(top) = max_heap.pop() {
8+
max_heap.push((top as f64).sqrt() as i32);
9+
}
10+
}
11+
max_heap.into_iter().map(|x| x as i64).sum()
12+
}
13+
}

0 commit comments

Comments
 (0)
0