class Solution:
def minimumDeviation(self, nums: List[int]) -> int:
heap = [-num*(1+(num&1)) for num in nums]
heapify(heap)
bot = -max(heap)
ans = 1000000001
while heap:
top = -heappop(heap)
ans = min(ans, top - bot)
if top&1:
break
else:
bot = min(bot, top>>1)
heappush(heap, -top>>1)
return ans
힙 쓰는 문제인건 보자마자 알았긴 한데...
배열에 넣고 heapify가 O(N)이고 heappush 연타가 O(NlogN)이라는데 속도 차이가 왜 없을까
댓글 0