mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
22 lines
424 B
Go
22 lines
424 B
Go
package leetcode
|
|
|
|
func numberOfBoomerangs(points [][]int) int {
|
|
res := 0
|
|
for i := 0; i < len(points); i++ {
|
|
record := make(map[int]int, len(points))
|
|
for j := 0; j < len(points); j++ {
|
|
if j != i {
|
|
record[dis(points[i], points[j])]++
|
|
}
|
|
}
|
|
for _, r := range record {
|
|
res += r * (r - 1)
|
|
}
|
|
}
|
|
return res
|
|
}
|
|
|
|
func dis(pa, pb []int) int {
|
|
return (pa[0]-pb[0])*(pa[0]-pb[0]) + (pa[1]-pb[1])*(pa[1]-pb[1])
|
|
}
|