We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 906d673 commit 0a2f632Copy full SHA for 0a2f632
447. Number of Boomerangs
@@ -0,0 +1,31 @@
1
+class Solution{
2
+ public int numberOfBoomerangs(int[][] points) {
3
+ int res = 0;
4
+
5
+ Map<Integer, Integer> map = new HashMap<>();
6
+ for(int i=0; i<points.length; i++) {
7
+ for(int j=0; j<points.length; j++) {
8
+ if(i == j)
9
+ continue;
10
11
+ int d = getDistance(points[i], points[j]);
12
+ map.put(d, map.getOrDefault(d, 0) + 1);
13
+ }
14
15
+ for(int val : map.values()) {
16
+ res += val * (val-1);
17
18
+ map.clear();
19
20
21
+ return res;
22
23
24
+ private int getDistance(int[] a, int[] b) {
25
+ int dx = a[0] - b[0];
26
+ int dy = a[1] - b[1];
27
28
+ return dx*dx + dy*dy;
29
30
31
+}
0 commit comments