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)이라는데 속도 차이가 왜 없을까
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.