作者DJYOSHITAKA (franchouchouISBEST)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Sat Jun 15 09:59:42 2024
502. IPO
維持maxheap內只有符合capital條件的profits即可
def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital:
List[int]) -> int:
l = sorted([(cap, pro) for cap, pro in zip(capital, profits)])
h = []
cur_i, n = 0, len(profits)
for i in range(k):
while cur_i<n and l[cur_i][0] <= w:
heappush(h, -l[cur_i][1])
cur_i += 1
if len(h)>0:
cur_profit = heappop(h)
w -= cur_profit
return w
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.228.146.144 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1718416785.A.CA6.html
→ JIWP: wwwww 06/15 10:00
→ JIWP: 別卷了 06/15 10:00
推 sustainer123: 大師 幫內推 06/15 10:01
推 SecondRun: 誰周末還刷題的 06/15 10:08