Leetcode/python/3066_minimum_operations_to_exceed_threshold_value_ii.py

10 lines
296 B
Python
Raw Permalink Normal View History

2024-03-08 16:42:50 +00:00
class Solution:
def minOperations(self, nums: List[int], k: int) -> int:
heapify(nums)
operations = 0
while (x := heappop(nums)) < k:
y = heappop(nums)
heappush(nums, min(x,y)*2 + max(x,y))
operations += 1
2024-03-08 16:52:26 +00:00
return operations