Skip to content

Commit 0a2f632

Browse files
authored
Create 447. Number of Boomerangs
1 parent 906d673 commit 0a2f632

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

447. Number of Boomerangs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)