每日一题 2558. 从数量最多的堆取走礼物(简单,heapq)

每日一题 2558. 从数量最多的堆取走礼物(简单,heapq)_第1张图片
怎么这么多天都是简单题,不多说了

class Solution:
    def pickGifts(self, gifts: List[int], k: int) -> int:
        gifts = [-gift for gift in gifts]
        heapify(gifts)
        for i in range(k):
            heappush(gifts, -int(sqrt(-heappop(gifts))))
        return -sum(gifts)

你可能感兴趣的:(用Python刷力扣,python,算法,leetcode)