-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path982.cpp
More file actions
27 lines (26 loc) · 819 Bytes
/
Copy path982.cpp
File metadata and controls
27 lines (26 loc) · 819 Bytes
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
class Solution {
public:
int countTriplets(vector<int> &A) {
int total = 0;
int size = A.size();
for (int i = 0; i < size - 2; ++i) {
for (int j = i + 1; j < size - 1; ++j)
for (int k = j + 1; k < size; ++k) {
if (static_cast<int>(A[i] & A[j] & A[k]) == 0)
total += 6;
}
}
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; ++j) {
if (i == j)
continue;
if (static_cast<int>(A[i] & A[i] & A[j]) == 0)
total += 3;
}
}
for (int i = 0; i < size; ++i)
if (static_cast<int>(A[i] & A[i] & A[i] ) == 0)
total += 1;
return total;
}
};