Re: [閒聊] 每日leetcode

看板Marginalman作者 (franchouchouISBEST)時間1年前 (2024/10/04 08:36), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串939/1548 (看更多)
好醜 醜吐我了 但我只求AC了 還要去公司 想那個了 def dividePlayers(self, skill: List[int]) -> int: summ = sum(skill) if summ%(len(skill)//2) != 0: return -1 target = sum(skill)//(len(skill)//2) cnt = defaultdict(int) for s in skill: cnt[s] += 1 ans = 0 for s in skill: if cnt[s] == 0: continue cnt[s] -= 1 if cnt[target-s] > 0: cnt[target-s] -= 1 else: return -1 ans += (target-s)*s return ans -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728002176.A.9F7.html
文章代碼(AID): #1c_pY0dt (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1c_pY0dt (Marginalman)