题目链接:https://leetcode-cn.com/problems/triples-with-bitwise-and-equal-to-zero/
题意:
给定一个整数数组 A,找出索引为 (i, j, k) 的三元组,使得:
0 <= i < A.length
0 <= j < A.length
0 <= k < A.length
A[i] & A[j] & A[k] == 0,其中 & 表示按位与(AND)操作符。
方法一:哈希表暴力解
class Solution {
public:
int countTriplets(vector<int>& nums) {
int total = 0;
unordered_map<int,int> mp1;//哈希表1,<数字,出现次数>
unordered_map<int,int> mp2;//哈希表2,<两数与的结果,出现次数>
for(int& num:nums)//更新哈希表1
{
mp1[num]++;
}
int len = nums.size();//统计nums的长度
for(int i=0;