/*
* @lc app=leetcode id=982 lang=cpp
*
* [982] Triples with Bitwise AND Equal To Zero
*/
// @lc code=start
class Solution {
public:
int countTriplets(vector<int>& nums) {
unordered_map<int, int> mp;
int N = nums.size();
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
mp[nums[i] & nums[j]] ++;
}
}
int ans = 0;
for(int i=0;i<N;i++){
for(auto v: mp){
if( (nums[i] & v.first) == 0 ) ans += v.second;
}
}
return ans;
}
};
// @lc code=end
No.285 - LeetCode[982] Triples with Bitwise AND Equal To Zero - 哈希降维
最新推荐文章于 2024-04-23 17:09:00 发布