1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public int numberOfBoomerangs(int[][] points) { int ans = 0; Map<Integer, Integer> cnt = new HashMap<>(); for (int[] p1 : points) { cnt.clear(); for (int[] p2 : points) { int d = (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]); int c = cnt.getOrDefault(d, 0); ans += c * 2; cnt.put(d, c + 1); } } return ans; } }
|