Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-06-28 08:31:18
cnt后然后cnt多的给大的权重这样
比昨天简单
昨天好难
==
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
cnt = [0 for _ in range(n)]
for road in roads:
node1, node2 = road
cnt[node1] += 1
cnt[node2] += 1
cnt.sort()
ans = 0
for i in range(n):
ans += (i+1)*cnt[i]
return ans
作者: rainkaras (rainkaras)   2024-06-28 08:40:00
大师
作者: sustainer123 (caster)   2024-06-28 08:50:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com