Re: [闲聊] 每日leetcode

楼主: DJYOSHITAKA (Evans)   2024-06-18 22:28:18
826. Most Profit Assigning Work
肥肥别的不懂
只懂得排序
def maxProfitAssignment(self, difficulty: List[int], profit: List[int],
worker: List[int]) -> int:
worker.sort()
difficulty, profit = zip(*sorted(zip(difficulty, profit)))
maximum_profit, idx, ans = 0, 0, 0
for d in worker:
while idx<len(difficulty) and d>=difficulty[idx]:
maximum_profit = max(maximum_profit, profit[idx])
idx += 1
ans += maximum_profit
return ans
作者: sustainer123 (caster)   2024-06-18 22:33:00
大师为啥你为啥zip又一个zip?那行不太懂 还有那星号
作者: oin1104 (是oin的说)   2024-06-18 22:50:00
大师
楼主: DJYOSHITAKA (Evans)   2024-06-18 22:55:00
sorted(zip)的结果会是list of n个tuple2 然后*解开会变成n个tuple2 再zip会变成两个tuple n应该是这样 我也刚学会:(
作者: CanIndulgeMe   2024-06-18 23:05:00
再卷下去,中国科技要起飞了

Links booklink

Contact Us: admin [ a t ] ucptt.com