This commit is contained in:
VicRen
2020-12-03 15:30:04 +08:00
parent 410825768e
commit e16c9db6e6
4 changed files with 114 additions and 3 deletions
+30
View File
@@ -0,0 +1,30 @@
package main
func main() {
}
func goodPairsCount(src []int) int {
count := 0
l := len(src)
for i := 0; i < l; i++ {
for j := i + 1; j < l; j++ {
if src[i] == src[j] {
count++
}
}
}
return count
}
func goodPairsCount2(src []int) int {
m := make(map[int]int)
for _, n := range src {
m[n] += 1
}
count := 0
for _, v := range m {
count += v * (v - 1) / 2
}
return count
}