-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path982.java
More file actions
48 lines (46 loc) · 1.27 KB
/
982.java
File metadata and controls
48 lines (46 loc) · 1.27 KB
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
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public int countTriplets(int[] A) {
int N = (1 << 16) - 1;
int[] ct = new int[N + 1];
int l = A.length;
for (int x : A) {
for (int k = x; k <= N; k = x | (k + 1)) {
++ct[k];
}
}
int res = 0;
for (int a : A) {
for (int b : A) {
res += ct[N ^ (a & b)];
}
}
return res;
}
}
__________________________________________________________________________________________________
sample 37148 kb submission
class Solution {
public int countTriplets(int[] A) {
int ans=0;
int []store= new int[1<<16];
for(int i=0;i<A.length;i++){
for(int j=0;j<A.length;j++)
{
store[A[i]&A[j]]++;
}
}
for(int i=0;i<A.length;i++)
{
for(int j=0;j<(1<<16);j++){
if((A[i]&j)==0)
{
ans+=store[j];
}
}
}
return ans;
}
}
__________________________________________________________________________________________________