Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/10/04 11:11), 編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串940/1548 (看更多)
2491. Divide Players Into Teams of Equal Skill ## 思路 chemistry會是最大跟最小的skill相加 排序後, 每次從頭尾各取一 如果相加的和不等於chemistry就回傳-1 ## Code ```python class Solution: def dividePlayers(self, skill: List[int]) -> int: skill.sort() res = 0 chemistry = skill[0] + skill[-1] for i in range(len(skill) // 2): if skill[i] + skill[~i] != chemistry: return -1 res += skill[i] * skill[~i] return res ``` -- https://i.imgur.com/kyBhy6o.jpeg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.129 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728011516.A.DEA.html

10/04 11:14, 1年前 , 1F
大師
10/04 11:14, 1F
文章代碼(AID): #1c_rpytg (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1c_rpytg (Marginalman)