Skip to content

Commit 32a2cb7

Browse files
add 2558
1 parent 700abbe commit 32a2cb7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 2558 |[Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2558.java) | | Easy |
1112
| 2554 |[Maximum Number of Integers to Choose From a Range I](https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2554.java) | | Medium |
1213
| 2553 |[Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2553.java) | | Easy |
1314
| 2549 |[Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2549.java) || Easy |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.PriorityQueue;
4+
5+
public class _2558 {
6+
public static class Solution1 {
7+
public long pickGifts(int[] gifts, int k) {
8+
PriorityQueue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);
9+
for (int g : gifts) {
10+
maxHeap.offer(g);
11+
}
12+
while (k-- > 0) {
13+
int max = maxHeap.poll();
14+
maxHeap.offer((int) Math.sqrt(max));
15+
}
16+
long res = 0l;
17+
while (!maxHeap.isEmpty()) {
18+
res += maxHeap.poll();
19+
}
20+
return res;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)