Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/10/14 09:54), 編輯推噓3(300)
留言3則, 3人參與, 1年前最新討論串983/1554 (看更多)
2530. Maximal Score After Applying K Operations ## 思路 MaxHeap取k次 ## Code ```python class Solution: def maxKelements(self, nums: List[int], k: int) -> int: res = 0 max_heap = [] for num in nums: heapq.heappush(max_heap, -num) for _ in range(k): num = -heapq.heappop(max_heap) res += num heapq.heappush(max_heap, -ceil(num/3)) return res ``` -- https://i.imgur.com/kyBhy6o.jpeg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.71 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728870844.A.FCA.html

10/14 09:54, 1年前 , 1F
法國我
10/14 09:54, 1F

10/14 09:56, 1年前 , 2F
別捲了
10/14 09:56, 2F

10/14 09:57, 1年前 , 3F
大師
10/14 09:57, 3F
文章代碼(AID): #1d37cy_A (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1d37cy_A (Marginalman)