Re: [闲聊] 每日leetcode

楼主: DJYOSHITAKA (Evans)   2024-06-15 09:59:42
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
作者: JIWP (JIWP)   2024-06-15 10:00:00
wwwww
作者: sustainer123 (caster)   2024-06-15 10:01:00
大师 帮内推
作者: SecondRun (雨夜琴声)   2024-06-15 10:08:00
谁周末还刷题的

Links booklink

Contact Us: admin [ a t ] ucptt.com