forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
37 lines (28 loc) · 748 Bytes
/
main.cpp
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
/// Source : https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero/
/// Author : liuyubobobo
/// Time : 2019-01-26
#include <iostream>
#include <vector>
using namespace std;
/// Using HashSet
/// Time Complexity: O(max(2^16 * n, n^2))
/// Space Complexity: O(2^16 * n)
class Solution {
public:
int countTriplets(vector<int>& A) {
int n = A.size();
vector<int> table(65536, 0);
for(int a: A)
for(int i = 0; i < 65536; i ++)
if(!(a & i))
table[i] ++;
int res = 0;
for(int i = 0; i < n; i ++)
for(int j = 0; j < n; j ++)
res += table[A[i] & A[j]];
return res;
}
};
int main() {
return 0;
}