- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3199.java
31 lines (29 loc) · 1.02 KB
/
_3199.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
packagecom.fishercoder.solutions.fourththousand;
publicclass_3199 {
publicstaticclassSolution1 {
publicinttripletCount(int[] a, int[] b, int[] c) {
intcount = 0;
for (inti = 0; i < a.length; i++) {
for (intj = 0; j < b.length; j++) {
for (intk = 0; k < c.length; k++) {
intxor = a[i] ^ b[j] ^ c[k];
if (evenSetBits(xor)) {
count++;
}
}
}
}
returncount;
}
privatebooleanevenSetBits(intnum) {
intbits = 0;
// this is the idea of calculating hamming weight:
// https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_191.java#L16_L23
while (num != 0) {
bits++;
num &= num - 1;
}
returnbits % 2 == 0;
}
}
}