-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #919 from 0xff-dev/2285
Add solution and test-cases for problem 2285
- Loading branch information
Showing
5 changed files
with
60 additions
and
26 deletions.
There are no files selected for viewing
46 changes: 32 additions & 14 deletions
46
leetcode/2201-2300/2285.Maximum-Total-Importance-of-Roads/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 18 additions & 2 deletions
20
leetcode/2201-2300/2285.Maximum-Total-Importance-of-Roads/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
import "sort" | ||
|
||
func Solution(n int, roads [][]int) int64 { | ||
ans := int64(0) | ||
|
||
// 检查入读和出度 | ||
in := make([]int, n) | ||
for _, r := range roads { | ||
in[r[0]]++ | ||
in[r[1]]++ | ||
} | ||
sort.Ints(in) | ||
v := int64(1) | ||
for _, i := range in { | ||
ans += v * int64(i) | ||
v++ | ||
} | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+24.8 KB
leetcode/2201-2300/2285.Maximum-Total-Importance-of-Roads/ex1drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.5 KB
leetcode/2201-2300/2285.Maximum-Total-Importance-of-Roads/ex2drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.