作者DJYOSHITAKA (franchouchouISBEST)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Tue Jun 18 22:28:18 2024
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
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.79.54.128 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1718720901.A.101.html
推 sustainer123: 大師 06/18 22:33
→ sustainer123: 為啥你為啥zip又一個zip?那行不太懂 還有那星號 06/18 22:34
推 oin1104: 大師 06/18 22:50
→ DJYOSHITAKA: sorted(zip)的結果會是list of n個tuple2 然後*解開 06/18 22:55
→ DJYOSHITAKA: 會變成n個tuple2 再zip會變成兩個tuple n 06/18 22:57
→ DJYOSHITAKA: 應該是這樣 我也剛學會:( 06/18 22:58
→ CanIndulgeMe: 再卷下去,中国科技要起飞了 06/18 23:05