Number of Boomerangs LeetCode solution in Java
1class Solution {2public int numberOfBoomerangs(int[][] points) {34int answer = 0;56for (int p = 0; p < points.length; p++) {78int[] i = points[p];910HashMap<Double, Integer> hm = new HashMap<Double, Integer>();1112for (int q = 0; q < points.length; q++) {1314if (q == p) {15continue;16}1718int[] j = points[q];1920double distance = Math.sqrt(Math.pow(j[0] - i[0], 2) + Math.pow(j[1] - i[1], 2));2122if (distance > 0) {23if (hm.containsKey(distance)) {24hm.put(distance, hm.get(distance) + 1);25} else {26hm.put(distance, 1);27}28}29}3031for (Double dist : hm.keySet()) {32int occ = hm.get(dist);33if (occ > 1) {34answer = answer + ((occ) * (occ - 1));35}36}37}3839return answer;40}41}