2208. Minimum Operations to Halve Array Sum
On This Page
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