1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution { public int numberOfBoomerangs(int[][] points) { int ans = 0; Map<Integer, Integer> distanceHash = new HashMap<>(); for (int[] point1 : points) { distanceHash.clear(); for (int[] point2 : points) { int distance = (point2[0] - point1[0]) * (point2[0] - point1[0]) + (point2[1] - point1[1]) * (point2[1] - point1[1]); distanceHash.put(distance, distanceHash.getOrDefault(distance, 0) + 1); } for (Map.Entry<Integer, Integer> entry : distanceHash.entrySet()) { int count = entry.getValue(); ans += (count - 1) * count; } } return ans; } }
|