mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
22 lines
332 B
Go
22 lines
332 B
Go
|
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
|
||
|
}
|