1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

go: add «2285. Maximum Total Importance of Roads»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-06-28 23:56:30 +02:00
parent b8af7f3e38
commit c56b3d121b
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,21 @@
package main
import "slices"
func maximumImportance(n int, roads [][]int) int64 {
degrees := make([]int64, n)
for _, edge := range roads {
degrees[edge[0]]++
degrees[edge[1]]++
}
slices.Sort(degrees)
importance := int64(0)
for i, degree := range degrees {
importance += int64(i+1) * degree
}
return importance
}