This commit is contained in:
parent
d8f26e03e8
commit
e959868af3
1 changed files with 20 additions and 0 deletions
20
medium/minimum_operations_to_exceed_threshold_value_ii.py
Normal file
20
medium/minimum_operations_to_exceed_threshold_value_ii.py
Normal 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
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue