2208. Minimum Operations to Halve Array Sum

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2208

class Solution:
    def halveArray(self, nums: List[int]) -> int:
        s = sum(nums) / 2
        h = []
        for v in nums:
            heappush(h, -v)
        res = 0
        while s > 0:
            t = -heappop(h) / 2
            s -= t
            heappush(h, -t)
            res += 1
        return res