-
Notifications
You must be signed in to change notification settings - Fork 14
/
Solution447.java
33 lines (28 loc) · 1.02 KB
/
Solution447.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package leetcode.hashmap;
import java.util.HashMap;
import java.util.Map;
public class Solution447 {
public static void main(String[] args) {
System.out.println(new Solution447().numberOfBoomerangs(new int[][]{
new int[]{0, 0}, new int[]{1, 0}, new int[]{2, 0}
}));
}
public int numberOfBoomerangs(int[][] points) {
int res = 0;
for (int i = 0; i < points.length; i++) {
HashMap<Integer, Integer> disCount = new HashMap<>();
for (int j = 0; j < points.length; j++) {
if (i == j) continue;
int x = points[j][0] - points[i][0];
int y = points[j][1] - points[i][1];
int dist = x * x + y * y;
disCount.put(dist, disCount.getOrDefault(dist, 0) + 1);
}
for (Map.Entry<Integer, Integer> entry : disCount.entrySet()) {
Integer num = entry.getValue();
res += num * (num - 1);
}
}
return res;
}
}