-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
447.java
61 lines (57 loc) · 1.83 KB
/
447.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
__________________________________________________________________________________________________
sample 42 ms submission
class Solution {
public int numberOfBoomerangs(int[][] p) {
int l = p.length;
int c[] = new int[l<<1];
int u = 0;
for(int pr[] : p){
c[u++] = pr[0];
c[u++] = pr[1];
}
int count = 0;
Map<Integer,Integer> map = new HashMap<>(u<<1);
for(int i=0;i<u;i+=2){
for(int j=0,x = c[i],y = c[i+1];j<u;j+=2){
int d = (x-c[j])*(x-c[j])+(y-c[j+1])*(y-c[j+1]);
Integer v = map.get(d);
if(v!=null){
map.put(d,v+1);
count+=v<<1;
} else
map.put(d,1);
}
map.clear();
}
return count;
}
}
__________________________________________________________________________________________________
sample 38236 kb submission
class Solution {
public int numberOfBoomerangs(int[][] p) {
int l = p.length;
int c[] = new int[l<<1];
int u = 0;
for(int pr[] : p){
c[u++] = pr[0];
c[u++] = pr[1];
}
int count = 0;
Map<Integer,Integer> map = new HashMap<>(u<<1);
for(int i=0;i<u;i+=2){
for(int j=0,x = c[i],y = c[i+1];j<u;j+=2){
int d = (x-c[j])*(x-c[j])+(y-c[j+1])*(y-c[j+1]);
Integer v = map.get(d);
if(v!=null){
map.put(d,v+1);
count+=v<<1;
} else
map.put(d,1);
}
map.clear();
}
return count;
}
}
__________________________________________________________________________________________________