Re: [閒聊] 每日leetcode

看板Marginalman作者 (franchouchouISBEST)時間1年前 (2024/06/18 22:28), 編輯推噓2(205)
留言7則, 4人參與, 1年前最新討論串380/1549 (看更多)
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

06/18 22:33, 1年前 , 1F
大師
06/18 22:33, 1F

06/18 22:34, 1年前 , 2F
為啥你為啥zip又一個zip?那行不太懂 還有那星號
06/18 22:34, 2F

06/18 22:50, 1年前 , 3F
大師
06/18 22:50, 3F

06/18 22:55, 1年前 , 4F
sorted(zip)的結果會是list of n個tuple2 然後*解開
06/18 22:55, 4F

06/18 22:57, 1年前 , 5F
會變成n個tuple2 再zip會變成兩個tuple n
06/18 22:57, 5F

06/18 22:58, 1年前 , 6F
應該是這樣 我也剛學會:(
06/18 22:58, 6F

06/18 23:05, 1年前 , 7F
再卷下去,中国科技要起飞了
06/18 23:05, 7F
文章代碼(AID): #1cSPc541 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cSPc541 (Marginalman)