bumpsoo 2025-02-13 11:47:17 +00:00
parent d8f26e03e8
commit e959868af3

View file

@ -0,0 +1,20 @@
# https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-ii
from typing import List
import heapq
class Solution:
def minOperations(self, nums: List[int], k: int) -> int:
q: List[int] = []
for num in nums:
heapq.heappush(q, num)
result = 0
while len(q) > 0:
x = heapq.heappop(q)
if x >= k:
break
y = heapq.heappop(q)
heapq.heappush(q, min(x, y) * 2 + max(x, y))
result += 1
return result