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:
parent
b8af7f3e38
commit
c56b3d121b
1 changed files with 21 additions and 0 deletions
21
go/maximum-total-importance-of-roads.go
Normal file
21
go/maximum-total-importance-of-roads.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue