Add solutions

This commit is contained in:
Kiril Kovachev 2024-03-08 16:42:50 +00:00
commit ed40cc2fd1
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,7 @@
class Solution:
def minOperations(self, nums: List[int], k: int) -> int:
heapify(nums)
operations = 0
while heappop(nums) < k:
operations += 1
return operations

View File

@ -0,0 +1,9 @@
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
return operations