Skip to content

Commit 820fd00

Browse files
committed
[LeetCode Sync] Runtime - 4 ms (62.67%), Memory - 17.4 MB (15.28%)
1 parent 3412c01 commit 820fd00

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def pickGifts(self, gifts: List[int], k: int) -> int:
3+
# py has min heap so use - minus sign to simulate max heap
4+
h = [-g for g in gifts]
5+
heapq.heapify(h)
6+
7+
for _ in range(k):
8+
maxElement = -heapq.heappop(h)
9+
10+
heapq.heappush(h, -math.floor(math.sqrt(maxElement)))
11+
12+
res = 0
13+
while h:
14+
# now use - to make it back positive
15+
res -= heapq.heappop(h)
16+
17+
return res

0 commit comments

Comments
 (0)