Skip to content

Commit 242ac1d

Browse files
committed
2285
1 parent 2dd60da commit 242ac1d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Jun-28-24.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
3+
d = defaultdict(int)
4+
for u,v in roads:
5+
d[u] += 1
6+
d[v] += 1
7+
for i in range(n):
8+
if i not in d:
9+
d[i] = 0
10+
l = sorted(d.items(),key= lambda x:x[1])
11+
cnt = 0
12+
i = 1
13+
for u,v in l:
14+
cnt += i*v
15+
i += 1
16+
return cnt

0 commit comments

Comments
 (0)