Re: [闲聊] 每日leetcode

楼主: dont   2024-12-12 18:59:38
2558. Take Gifts From the Richest Pile
## 思路
max heap
## Code
```python
class Solution:
def pickGifts(self, gifts: List[int], k: int) -> int:
max_heap = [-val for val in gifts]
heapq.heapify(max_heap)
for _ in range(k):
num = -heapq.heappop(max_heap)
heapq.heappush(max_heap, -isqrt(num))
return -sum(max_heap)
```

Links booklink

Contact Us: admin [ a t ] ucptt.com